oci_instance – Launch, terminate and control the lifecycle of OCI Compute instances

New in version 2.5.

Synopsis

  • This module allows the user to launch/create, terminate and perform other power actions on OCI Compute Service instances. An instance represents a compute host. The image used to launch the instance determines its operating system and other software. The shape specified during the launch process determines the number of CPUs and memory allocated to the instance. For more information, see Overview of the Compute Service at https://docs.us-phoenix-1.oraclecloud.com/Content/Compute/Concepts/computeoverview.htm. In experimental mode, this module also allows attaching/detaching volumes and boot volumes to an instance.

Requirements

The below requirements are needed on the host that executes this module.

Parameters

Parameter Choices/Defaults Comments
api_user
string
The OCID of the user, on whose behalf, OCI APIs are invoked. If not set, then the value of the OCI_USER_OCID environment variable, if any, is used. This option is required if the user is not specified through a configuration file (See config_file_location). To get the user's OCID, please refer https://docs.us-phoenix-1.oraclecloud.com/Content/API/Concepts/apisigningkey.htm.
api_user_fingerprint
string
Fingerprint for the key pair being used. If not set, then the value of the OCI_USER_FINGERPRINT environment variable, if any, is used. This option is required if the key fingerprint is not specified through a configuration file (See config_file_location). To get the key pair's fingerprint value please refer https://docs.us-phoenix-1.oraclecloud.com/Content/API/Concepts/apisigningkey.htm.
api_user_key_file
string
Full path and filename of the private key (in PEM format). If not set, then the value of the OCI_USER_KEY_FILE variable, if any, is used. This option is required if the private key is not specified through a configuration file (See config_file_location). If the key is encrypted with a pass-phrase, the api_user_key_pass_phrase option must also be provided.
api_user_key_pass_phrase
string
Passphrase used by the key referenced in api_user_key_file, if it is encrypted. If not set, then the value of the OCI_USER_KEY_PASS_PHRASE variable, if any, is used. This option is required if the key passphrase is not specified through a configuration file (See config_file_location).
auth_type
string
    Choices:
  • api_key ←
  • instance_principal
The type of authentication to use for making API requests. By default auth_type="api_key" based authentication is performed and the API key (see api_user_key_file) in your config file will be used. If this 'auth_type' module option is not specified, the value of the OCI_ANSIBLE_AUTH_TYPE, if any, is used. Use auth_type="instance_principal" to use instance principal based authentication when running ansible playbooks within an OCI compute instance.
availability_domain
-
The Availability Domain of the instance. Required when creating a compute instance with state=present.
boot_volume_details
-
Details for attaching/detaching a boot volume to/from an instance. boot_volume_details is mutually exclusive with image_id. This option is only supported in experimental mode. To use an experimental feature, set the environment variable OCI_ANSIBLE_EXPERIMENTAL to True.
attachment_state
-
    Choices:
  • present ←
  • absent
Attach a boot volume to the instance instance_id with attachment_state=present. Detach a boot volume from the instance instance_id with attachment_state=absent.
boot_volume_id
- / required
The OCID of the boot volume.
compartment_id
-
The OCID of the compartment. Required when state=present.
config_file_location
string
Path to configuration file. If not set then the value of the OCI_CONFIG_FILE environment variable, if any, is used. Otherwise, defaults to ~/.oci/config.
config_profile_name
string
The profile to load from the config file referenced by config_file_location. If not set, then the value of the OCI_CONFIG_PROFILE environment variable, if any, is used. Otherwise, defaults to the "DEFAULT" profile in config_file_location.
defined_tags
dictionary
Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see https://docs.us-phoenix-1.oraclecloud.com/Content/General/Concepts/resourcetags.htm.
display_name
-
A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information.

aliases: name
extended_metadata
-
Additional metadata key/value pairs that you provide. They serve a similar purpose and functionality from fields in the metadata object. They are distinguished from metadata fields in that these can be nested JSON objects (whereas 'metadata' fields are string/string maps only). If you don't need nested metadata values, it is strongly advised to avoid using this object and use the Metadata object instead.
fault_domain
-
A fault domain is a grouping of hardware and infrastructure within an availability domain. Each availability domain contains three fault domains. Fault domains let you distribute your instances so that they are not on the same physical hardware within a single availability domain. A hardware failure or Compute hardware maintenance that affects one fault domain does not affect instances in other fault domains. If you do not specify the fault domain, the system selects one for you. To change the fault domain for an instance, terminate it and launch a new instance in the preferred fault domain. To get a list of fault domains, use oci_fault_domain_facts.
force_create
boolean
    Choices:
  • no ←
  • yes
Whether to attempt non-idempotent creation of a resource. By default, create resource is an idempotent operation, and doesn't create the resource if it already exists. Setting this option to true, forcefully creates a copy of the resource, even if it already exists.This option is mutually exclusive with key_by.
freeform_tags
dictionary
Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see https://docs.us-phoenix-1.oraclecloud.com/Content/General/Concepts/resourcetags.htm.
image_id
-
The OCID of the image used to boot the instance. image_id is mutually exclusive with boot_volume_details and source_details. This option is deprecated. Use source_details with source_type=image instead.
instance_id
-
The OCID of the compute instance. Required for updating an existing compute instance when state=present, for performing power actions (such as start, stop, softreset or reset) on an instance, and for terminating an instance state=absent.

aliases: id
ipxe_script
-
custom iPXE script that will run when the instance boots.
key_by
list
The list of comma-separated attributes of this resource which should be used to uniquely identify an instance of the resource. By default, all the attributes of a resource except freeform_tags are used to uniquely identify a resource.
metadata
-
A hash/dictionary of custom key/value pairs that are associated with the instance. This option is also used to provide information to cloud-init and specifying "ssh_authorized_keys" for the default user of the instance. This hash is specified as '{"key":"value"}' and '{"key":"value","key":"value"}'.
preserve_boot_volume
boolean
    Choices:
  • no ←
  • yes
Whether to preserve the boot volume when terminating an instance with state=absent.
region
string
The Oracle Cloud Infrastructure region to use for all OCI API requests. If not set, then the value of the OCI_REGION variable, if any, is used. This option is required if the region is not specified through a configuration file (See config_file_location). Please refer to https://docs.us-phoenix-1.oraclecloud.com/Content/General/Concepts/regions.htm for more information on OCI regions.
shape
-
The shape of the instance. Required when creating a compute instance with state=present.
source_details
- / required
Details for creating an instance. Use this parameter to specify whether a boot volume or an image should be used to launch a new instance.
boot_volume_id
-
The OCID of the boot volume used to boot the instance. Required if source_type is "bootVolume".
boot_volume_size_in_gbs
-
The size of the boot volume in GBs. Minimum value is 50 GB and maximum value is 16384 GB (16TB). Applicable only when source_type=image.
image_id
-
The OCID of the image used to boot the instance. Required if source_type is "image".
source_type
- / required
    Choices:
  • image
  • bootVolume
The source type for the instance. Use image when specifying the image OCID. Use bootVolume when specifying the boot volume OCID.
state
-
    Choices:
  • present ←
  • absent
  • running
  • reset
  • softreset
  • stopped
The state of the instance that must be asserted to. When state=present, and the compute instance doesn't exist, the instance is launched/created with the specified details. When state=absent, the compute instance is terminated. When state=stopped, the compute instance is powered off. When state=running, the compute instance is powered on. When state=softreset, an ACPI shutdown is initiated and the compute instance is powered on. When state=reset, the compute instance is powered off and then powered on. Note that state=softreset and state=reset states are not idempotent. Every time a play is executed with these state options, a shutdown and a power on sequence is executed against the instance.
tenancy
string
OCID of your tenancy. If not set, then the value of the OCI_TENANCY variable, if any, is used. This option is required if the tenancy OCID is not specified through a configuration file (See config_file_location). To get the tenancy OCID, please refer https://docs.us-phoenix-1.oraclecloud.com/Content/API/Concepts/apisigningkey.htm
vnic
-
Details for the primary VNIC that is automatically created and attached when the instance is launched. Required when creating a compute instance with state=present.

aliases: create_vnic_details
assign_public_ip
-
Determines whether the VNIC should be assigned a public IP address. If not set and the VNIC is being created in a private subnet (that is, where prohibitPublicIpOnVnic = true in the Subnet), then no public IP address is assigned. If not set and the subnet is public prohibitPublicIpOnVnic = false, then a public IP address is assigned. If set to true and prohibitPublicIpOnVnic = true, an error is returned.
hostname_label
-
The hostname for the VNIC's primary private IP. Used for DNS. The value is the hostname portion of the primary private IP's fully qualified domain name (FQDN) (for example, bminstance-1 in FQDN bminstance-1.subnet123.vcn1.oraclevcn.com). Must be unique across all VNICs in the subnet and comply with RFC 952 and RFC 1123.
name
-
A user-friendly name for the VNIC. Does not have to be unique.
private_ip
-
The private IP to assign to the VNIC. Must be an available IP address within the subnet's CIDR. If you don't specify a value, Oracle automatically assigns a private IP address from the subnet. This is the VNIC's primary private IP address.
skip_source_dest_check
-
Default:
"no"
Determines whether the source/destination check is disabled on the VNIC. Defaults to false, which means the check is performed.
subnet_id
- / required
The OCID of the subnet to create the VNIC in.
volume_details
-
Details for attaching or detaching a volume to an instance with state=present or state=RUNNING. This option is only supported in experimental mode. To use an experimental feature, set the environment variable OCI_ANSIBLE_EXPERIMENTAL to True.
attachment_name
-
A user-friendly name. Does not have to be unique, and it cannot be changed. Avoid entering confidential information.
attachment_state
-
    Choices:
  • present ←
  • absent
Attach a volume to the instance instance_id with attachment_state=present. Detach a volume from the instance instance_id with attachment_state=absent.
type
-
    Choices:
  • iscsi ←
The type of volume. The only supported value is "iscsi".
volume_id
-
The OCID of the volume to be attached to or detached from the instance instance_id.
wait
boolean
    Choices:
  • no
  • yes ←
Whether to wait for create or delete operation to complete.
wait_timeout
integer
Default:
1200
Time, in seconds, to wait when wait=yes.
wait_until
string
The lifecycle state to wait for the resource to transition into when wait=yes. By default, when wait=yes, we wait for the resource to get into ACTIVE/ATTACHED/AVAILABLE/PROVISIONED/ RUNNING applicable lifecycle state during create operation & to get into DELETED/DETACHED/ TERMINATED lifecycle state during delete operation.

Examples

- name: Launch/create an instance using an image, with custom metadata and a private IP assignment
  oci_instance:
     name: myinstance1
     availability_domain: "BnQb:PHX-AD-1"
     compartment_id: "ocid1.compartment.oc1..xxxxxEXAMPLExxxxx...vm62xq"
     shape: "BM.Standard1.36"
     metadata:
        foo: bar
        baz: quux
     source_details:
        source_type: image
        image_id: ocid1.image.oc1.phx.xxxxxEXAMPLExxxxx
     volume_details:
        attachment_state: present
        volume_id: ocid1.volume.oc1.phx.xxxxxEXAMPLExxxxx
     vnic:
        hostname_label: "myinstance1"
        private_ip: "10.0.0.5"
        subnet_id: "ocid1.subnet.oc1.phx.xxxxxEXAMPLExxxxx...5iddusmpqpaoa"

- name: Launch/create an instance using a boot volume, a private IP assignment and attach a volume, and a specific
        fault domain
  oci_instance:
     name: myinstance2
     availability_domain: "BnQb:PHX-AD-1"
     fault_domain: "FAULT-DOMAIN-2"
     source_details:
        source_type: bootVolume
        boot_volume_id: ocid1.bootvolume.oc1.iad.xxxxxEXAMPLExxxxx
     compartment_id: "ocid1.compartment.oc1..xxxxxEXAMPLExxxxx...vm62xq"
     shape: "BM.Standard1.36"
     volume_details:
        attachment_state: present
        volume_id: ocid1.volume.oc1.phx.xxxxxEXAMPLExxxxx
     vnic:
        hostname_label: "myinstance2"
        private_ip: "10.0.0.6"
        subnet_id: "ocid1.subnet.oc1.phx.xxxxxEXAMPLExxxxx...5iddusmpqpaoa"

- name: Launch/create an instance using an image with custom boot volume size
  oci_instance:
     name: myinstance1
     availability_domain: "BnQb:PHX-AD-1"
     compartment_id: "ocid1.compartment.oc1..xxxxxEXAMPLExxxxx...vm62xq"
     shape: "BM.Standard1.36"
     source_details:
        source_type: image
        image_id: ocid1.image.oc1.phx.xxxxxEXAMPLExxxxx
        boot_volume_size_in_gbs: 100
     vnic:
        hostname_label: "myinstance1"
        subnet_id: "ocid1.subnet.oc1.phx.xxxxxEXAMPLExxxxx...5iddusmpqpaoa"

- name: Update an instance's name
  oci_instance:
     name: myinstance1-new-name
     id: "ocid1.instance.oc1.phx.xxxxxEXAMPLExxxxx...lxiggdq"

- name: Detach a volume from an instance
  oci_instance:
     id: "ocid1.instance.oc1.phx.xxxxxEXAMPLExxxxx...lxiggdq"
     volume_details:
        attachment_state: absent
        volume_id: ocid1.volume.oc1.phx.xxxxxEXAMPLExxxxx

- name: Stop an instance
  oci_instance:
     id: "ocid1.instance.oc1.phx.xxxxxEXAMPLExxxxx...lxiggdq"
     state: "stopped"

- name: Stop an instance and detach boot volume
  oci_instance:
     id: "ocid1.instance.oc1.phx.xxxxxEXAMPLExxxxx...lxiggdq"
     state: "stopped"
     boot_volume_details:
        boot_volume_id: ocid1.bootvolume.oc1.iad.xxxxxEXAMPLExxxxx
        attachment_state: absent

- name: Attach a boot volume & Start an instance
  oci_instance:
     id: "ocid1.instance.oc1.phx.xxxxxEXAMPLExxxxx...lxiggdq"
     state: "running"
     boot_volume_details:
        boot_volume_id: ocid1.bootvolume.oc1.iad.xxxxxEXAMPLExxxxx

- name: Reset an instance
  oci_instance:
     id: "ocid1.instance.oc1.phx.xxxxxEXAMPLExxxxx...lxiggdq"
     state: "reset"

- name: Terminate/delete an instance
  oci_instance:
     id: "ocid1.instance.oc1.phx.xxxxxEXAMPLExxxxx...lxiggdq"
     state: "absent"

- name: Terminate/delete an instance and preserve boot volume
  oci_instance:
     id: "ocid1.instance.oc1.phx.xxxxxEXAMPLExxxxx...lxiggdq"
     state: "absent"
     preserve_boot_volume: yes

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description
instance
complex
On successful operation (create, update and terminate) on a single Compute instance
Details of the OCI compute instance launched, updated or terminated as a result of the current operation

Sample:
[{'lifecycle_state': 'RUNNING', 'fault_domain': 'FAULT-DOMAIN-1', 'extended_metadata': {}, 'compartment_id': 'ocid1.compartment.oc1..xxxxxEXAMPLExxxxx...vm62xq', 'region': 'phx', 'time_created': '2017-11-14T16:09:07.557000+00:00', 'display_name': 'ansible-test-968', 'image_id': 'ocid1.image.oc1.phx.xxxxxEXAMPLExxxxx....7klnoa', 'shape': 'BM.Standard1.36', 'availability_domain': 'BnQb:PHX-AD-1', 'volume_attachments': [{'lifecycle_state': 'ATTACHED', 'availability_domain': 'BnQb:PHX-AD-1', 'display_name': 'ansible_volume_attachment', 'compartment_id': 'ocid1.compartment.oc1..xxxxxEXAMPLExxxxx', 'chap_username': None, 'time_created': '2017-11-23T11:17:50.139000+00:00', 'id': 'ocid1.volumeattachment.oc1.phx.xxxxxEXAMPLExxxxx', 'instance_id': 'ocid1.instance.oc1.phx.xxxxxEXAMPLExxxxx', 'iqn': 'iqn.2015-12.com.oracleiaas:472a085d-41a9-4c18-ae7d-dea5b296dad3', 'ipv4': '169.254.2.2', 'volume_id': 'ocid1.volume.oc1.phx.xxxxxEXAMPLExxxxx', 'attachment_type': 'iscsi', 'port': 3260, 'chap_secret': None}], 'ipxe_script': None, 'boot_volume_attachment': {'boot_volume_id': 'ocid1.bootvolume.oc1.iad.xxxxxEXAMPLExxxxx', 'availability_domain': 'IwGV:US-ASHBURN-AD-1', 'display_name': 'Remote boot attachment for instance', 'compartment_id': 'ocid1.compartment.oc1..xxxxxEXAMPLExxxxx', 'lifecycle_state': 'ATTACHED', 'time_created': '2018-01-15T07:23:10.838000+00:00', 'instance_id': 'ocid1.instance.oc1.iad.xxxxxEXAMPLExxxxx', 'id': 'ocid1.instance.oc1.iad.xxxxxEXAMPLExxxxx'}, 'id': 'ocid1.instance.oc1.phx.xxxxxEXAMPLExxxxx....lxiggdq', 'metadata': {'foo': 'bar', 'baz': 'quux'}}]
  availability_domain
string
always
The Availability Domain the instance is running in.

Sample:
BnQb:PHX-AD-1
  boot_volume_attachment
dictionary
In experimental mode.
Information of the boot volume attachment.

    availability_domain
string
always
The Availability Domain of the instance.

Sample:
BnQb:PHX-AD-1
    boot_volume_id
string
always
The OCID of the boot volume.

Sample:
ocid1.bootvolume.oc1.iad.xxxxxEXAMPLExxxxx
    compartment_id
string
always
The OCID of the compartment.

Sample:
ocid1.compartment.oc1..xxxxxEXAMPLExxxxx
    display_name
string
always
A user-friendly name. Does not have to be unique, and it cannot be changed.

Sample:
My boot volume attachment
    id
string
always
The OCID of the boot volume attachment.

Sample:
ocid1.instance.oc1.iad.xxxxxEXAMPLExxxxx
    instance_id
string
always
The OCID of the instance the boot volume is attached to.

Sample:
ocid1.instance.oc1.phx.xxxxxEXAMPLExxxxx
    lifecycle_state
string
always
The current state of the boot volume attachment.

Sample:
ATTACHED
    time_created
string
always
The date and time the boot volume was created, in the format defined by RFC3339.

Sample:
2016-08-25 21:10:29.600000
  compartment_id
string
always
The OCID of the compartment that contains the instance.

Sample:
ocid1.compartment.oc1..xxxxxEXAMPLExxxxx....62xq
  display_name
string
always
A user-friendly name for the instance

Sample:
ansible-instance-968
  extended_metadata
dict(str, str)
always
Additional key-value pairs associated with the instance

Sample:
{'foo': 'bar'}
  fault_domain
string
always
The name of the fault domain the instance is running in. A fault domain is a grouping of hardware and infrastructure within an availability domain. Each availability domain contains three fault domains. Fault domains let you distribute your instances so that they are not on the same physical hardware within a single availability domain. A hardware failure or Compute hardware maintenance that affects one fault domain does not affect instances in other fault domains. If you do not specify the fault domain, the system selects one for you. To change the fault domain for an instance, terminate it and launch a new instance in the preferred fault domain.

Sample:
FAULT-DOMAIN-1
  id
string
always
The OCID of the instance.

Sample:
ocid1.instance.oc1.phx.xxxxxEXAMPLExxxxx
  image_id
string
always
The OCID of the image that the instance is based on

Sample:
ocid1.image.oc1.iad.xxxxxEXAMPLExxxxx
  ipxe_script
string
always
A custom iPXE script that will run when the instance boots

  lifecycle_state
string
always
The current state of the instance.

Sample:
TERMINATED
  metadata
dict(str, str)
always
Custom metadata that was associated with the instance

Sample:
{'foo': 'bar'}
  region
string
always
The region that contains the Availability Domain the instance is running in.

Sample:
phx
  shape
string
always
The shape of the instance. The shape determines the number of CPUs and the amount of memory allocated to the instance.

Sample:
BM.Standard1.36
  time_created
string
always
The date and time the instance was created, in the format defined by RFC3339

Sample:
2017-11-20 04:52:54.541000
  volume_attachments
complex
In experimental mode.
List of information about volume attachments

    attachment_type
string
always
The type of volume attachment.

Sample:
iscsi
    availability_domain
string
always
The Availability Domain of an instance.

Sample:
BnQb:PHX-AD-1
    chap_secret
string
always
The Challenge-Handshake-Authentication-Protocol (CHAP) secret valid for the associated CHAP user name. (Also called the "CHAP password".)

Sample:
d6866c0d-298b-48ba-95af-309b4faux45e
    chap_username
string
always
The volume's system-generated Challenge-Handshake-Authentication-Protocol (CHAP) user name.

Sample:
ocid1.volume.oc1.phx.xxxxxEXAMPLExxxxx
    compartment_id
string
always
The OCID of the compartment.

Sample:
ocid1.compartment.oc1..xxxxxEXAMPLExxxxx
    display_name
string
always
A user-friendly name. Does not have to be unique, and it cannot be changed.

Sample:
My volume attachment
    id
string
always
The OCID of the volume attachment.

Sample:
ocid1.volumeattachment.oc1.phx.xxxxxEXAMPLExxxxx
    instance_id
string
always
The OCID of the instance the volume is attached to.

Sample:
ocid1.instance.oc1.phx.xxxxxEXAMPLExxxxx
    ipv4
string
always
The volume's iSCSI IP address.

Sample:
169.254.0.2
    iqn
string
always
The target volume's iSCSI Qualified Name in the format defined by RFC 3720.

Sample:
iqn.2015-12.us.oracle.com:456b0391-17b8-4122-bbf1-f85fc0bb97d9
    lifecycle_state
string
always
The current state of the volume attachment.

Sample:
ATTACHED
    port
integer
always
The volume's iSCSI port.

Sample:
3260
    time_created
string
always
The date and time the volume was created, in the format defined by RFC3339.

Sample:
2016-08-25 21:10:29.600000
    volume_id
string
always
The OCID of the volume.

Sample:
ocid1.volume.oc1.phx.xxxxxEXAMPLExxxxx


Status

  • This module is not guaranteed to have a backwards compatible interface. [preview]
  • This module is maintained by the Ansible Community. [community]

Authors

  • Sivakumar Thyagarajan (@sivakumart)

Hint

If you notice any issues in this documentation you can edit this document to improve it.