gcore.cloud.instance (1.0.1) — module

Manages instances.

Authors: GCore (@GCore)

Install collection

Install with ansible-galaxy collection install gcore.cloud:==1.0.1


Add to requirements.yml

  collections:
    - name: gcore.cloud
      version: 1.0.1

Description

Create, update, delete, start, stop, powercycle, reboot, suspend, resume, add_to_servergroup or remove_from_servergroup.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create instance from volume
  gcore.cloud.instance:
    api_key: "{{ api_key }}"
    region_id: "{{ region_id }}"
    project_id: "{{ project_id }}"
    command: create
    names: [Test]
    flavor: g1-standard-1-2
    volumes: [{
        'source': 'image',
        'image_id': '55d662eb-b2d5-4b3c-bc84-a2265e25c86e',
        'size': 20,
        'boot_index': 0,
    }]
    interfaces: [{
        'type': 'external'
    }]
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create instance from snapshot
  gcore.cloud.instance:
    api_key: "{{ api_key }}"
    region_id: "{{ region_id }}"
    project_id: "{{ project_id }}"
    command: create
    names: [Test]
    flavor: g1-standard-1-2
    volumes: [{
        'source': 'snapshot',
        'image_id': '55d662eb-b2d5-4b3c-bc84-a2265e25c86e',
        'size': 20,
        'boot_index': 0,
    }]
    interfaces: [{
        'type': 'external'
    }]
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Rename instance
  gcore.cloud.instance:
    api_key: "{{ api_key }}"
    region_id: "{{ region_id }}"
    project_id: "{{ project_id }}"
    command: update
    instance_id: "{{ instance_id }}"
    name: "new-name"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Stop instance
  gcore.cloud.instance:
    api_key: "{{ api_key }}"
    region_id: "{{ region_id }}"
    project_id: "{{ project_id }}"
    command: stop
    instance_id: "{{ instance_id }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Start instance
  gcore.cloud.instance:
    api_key: "{{ api_key }}"
    region_id: "{{ region_id }}"
    project_id: "{{ project_id }}"
    command: start
    instance_id: "{{ instance_id }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Powercycle instance
  gcore.cloud.instance:
    api_key: "{{ api_key }}"
    region_id: "{{ region_id }}"
    project_id: "{{ project_id }}"
    command: powercycle
    instance_id: "{{ instance_id }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Reboot instance
  gcore.cloud.instance:
    api_key: "{{ api_key }}"
    region_id: "{{ region_id }}"
    project_id: "{{ project_id }}"
    command: reboot
    instance_id: "{{ instance_id }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Suspend instance
  gcore.cloud.instance:
    api_key: "{{ api_key }}"
    region_id: "{{ region_id }}"
    project_id: "{{ project_id }}"
    command: suspend
    instance_id: "{{ instance_id }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Resume instance
  gcore.cloud.instance:
    api_key: "{{ api_key }}"
    region_id: "{{ region_id }}"
    project_id: "{{ project_id }}"
    command: resume
    instance_id: "{{ instance_id }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Delete instance
  gcore.cloud.instance:
    api_key: "{{ api_key }}"
    region_id: "{{ region_id }}"
    project_id: "{{ project_id }}"
    command: delete
    instance_id: "{{ instance_id }}"

Inputs

    
name:
    description:
    - New instance names.
    - Required if I(command) is update.
    required: false
    type: str

names:
    description:
    - List of instance names.
    - Required if I(command) is create and I(name_templates) are not passed.
    elements: str
    required: false
    type: list

flavor:
    description:
    - Flavor ID.
    - Required if I(command) is create.
    required: false
    type: str

api_key:
    description:
    - GCore API auth key
    - Can be passed as I(CLOUD_API_KEY) environment variable.
    type: str

command:
    choices:
    - create
    - update
    - delete
    - start
    - stop
    - powercycle
    - reboot
    - suspend
    - resume
    - add_to_servergroup
    - remove_from_servergroup
    description:
    - Operation to perform.
    required: true
    type: str

volumes:
    description:
    - List of volumes for instances.
    - Required if I(command) is create.
    elements: dict
    required: false
    type: list

api_host:
    default: https://api.gcore.com/cloud
    description:
    - GCore API base host
    - Can be passed as I(CLOUD_API_HOST) environment variable.
    type: str

metadata:
    description:
    - Create one or more metadata items for an instance.
    - Optional if I(command) is create.
    required: false
    type: dict

password:
    description:
    - A password for VM. This parameter is used to set a password for the Admin.
    - Optional if I(command) is create.
    required: false
    type: str

username:
    description:
    - A name of a new user in the Linux VM. It may be passed with a password parameter.
    - Optional if I(command) is create.
    required: false
    type: str

floatings:
    description:
    - Floating ids that should be deleted.
    - Optional if I(command) is delete.
    elements: str
    required: false
    type: list

region_id:
    description:
    - GCore API region ID
    - Required if I(region_name) is not passed
    - Can be passed as I(CLOUD_REGION_ID) environment variable.
    type: int

user_data:
    description:
    - String in base64 format. Must not be passed together with username or password.
    - Optional if I(command) is create.
    required: false
    type: str

interfaces:
    description:
    - Subnet IPs and floating IPs.
    - Required if I(command) is create.
    elements: dict
    required: false
    type: list

project_id:
    description:
    - GCore API project ID
    - Required if I(project_name) is not passed
    - Can be passed as I(CLOUD_PROJECT_ID) environment variable.
    type: int

api_timeout:
    default: 30
    description:
    - Timeout in seconds to polling GCore API
    type: int

instance_id:
    description:
    - Instance ID.
    - Required for some operations.
    required: false
    type: str

region_name:
    description:
    - GCore API region name
    - Required if I(region_id) is not passed
    - Can be passed as I(CLOUD_REGION_NAME) environment variable.
    type: str

keypair_name:
    description:
    - Keypair name to inject into new instance(s).
    - Optional if I(command) is create.
    required: false
    type: str

project_name:
    description:
    - GCore API project name
    - Required if I(project_id) is not passed
    - Can be passed as I(CLOUD_PROJECT_NAME) environment variable.
    type: str

configuration:
    description:
    - Parameters for the application template from the marketplace.
    - Optional if I(command) is create.
    required: false
    type: dict

name_templates:
    description:
    - List of instance names which will be changed by template.
    - You can use forms ip_octets, two_ip_octets, one_ip_octet.
    - Required if I(command) is create and I(names) are not passed.
    elements: str
    required: false
    type: list

servergroup_id:
    description:
    - Anti-affinity or affinity or soft-anti-affinity server group ID.
    - Optional if I(command) is create.
    - Required if I(command) is add_to_servergroup.
    required: false
    type: str

allow_app_ports:
    description:
    - If true, application ports will be allowed in the security group for instances created
      from
    - the marketplace application template.
    - Optional if I(command) is create.
    required: false
    type: bool

security_groups:
    description:
    - Security group UUIDs.
    - Optional if I(command) is create.
    elements: dict
    required: false
    type: list

activate_profile:
    description:
    - Should ddos_profile be activated.
    - Optional if I(command) is start.
    required: false
    type: bool

volumes_to_delete:
    description:
    - Comma separated list of volume IDs to be deleted with the instance.
    - Used if I(command) is delete.
    required: false
    type: str

reserved_fixed_ips:
    description:
    - Port IDs to be deleted with the instance.
    - Optional if I(command) is delete.
    elements: str
    required: false
    type: list

Outputs

instance_info:
  contains:
    addresses:
      description: Map of network_name
      returned: always
      sample:
        net1:
        - addr: 10.0.0.17
          subnet_id: 91200a6c-07e0-42aa-98da-32d1f6545ae7
          subnet_name: string
          type: fixed
        - addr: 92.38.157.215
          subnet_id: 91200a6c-07e0-42aa-98da-32d1f6545ae7
          subnet_name: string
          type: floating
        net2:
        - addr: 192.168.68.68
          subnet_id: 91200a6c-07e0-42aa-98da-32d1f6545ae7
          subnet_name: string
          type: fixed
      type: dict
    blackhole_ports:
      description: IP addresses of the instances that are blackholed by DDoS mitigation
        system
      returned: if available
      sample:
      - AlarmEnd: '2021-03-17T16:24:06'
        AlarmStart: '2021-03-17T14:24:06'
        AlarmState: ALARM
        AlertDuration: 2 hours
        DestinationIP: 92.38.162.134
        ID: 1
      type: list
    creator_task_id:
      description: Task that created this entity
      returned: if available
      sample: d1e1500b-e2be-40aa-9a4b-cc493fa1af30
      type: str
    flavor:
      description: Flavor
      returned: always
      sample:
        disk: 0
        flavor_id: g1s-shared-1-0.5
        flavor_name: g1s-shared-1-0.5
        ram: 512
        vcpus: 1
      type: dict
    instance_created:
      description: Datetime when instance was created
      returned: always
      sample: '2019-07-11T06:58:48Z'
      type: str
    instance_description:
      description: Instance description
      returned: always
      sample: Testing
      type: str
    instance_id:
      description: Region ID
      returned: always
      sample: a7e7e8d6-0bf7-4ac9-8170-831b47ee2ba9
      type: str
    instance_name:
      description: Instance name
      returned: always
      sample: Testing
      type: str
    keypair_name:
      description: Keypair name
      returned: always
      sample: None
      type: str
    metadata:
      description: Metadata
      returned: if available
      sample:
        image_id: f01fd9a0-9548-48ba-82dc-a8c8b2d6f2f1
        image_name: cirros-0.3.5-x86_64-disk
        os_distro: centos
        os_version: 1711-x64
        snapshot_id: c286cd13-fba9-4302-9cdb-4351a05a56ea
        snapshot_name: test_snapshot
        task_id: d1e1500b-e2be-40aa-9a4b-cc493fa1af30
      type: dict
    metadata_detailed:
      description: Detailed VM metadata
      returned: if available
      sample:
      - key: task_id
        read_only: true
        value: d1e1500b-e2be-40aa-9a4b-cc493fa1af30
      type: list
    project_id:
      description: Project ID
      returned: always
      sample: 1
      type: int
    region:
      description: Region name
      returned: always
      sample: Luxembourg 1
      type: str
    region_id:
      description: Region ID
      returned: always
      sample: 1
      type: int
    security_groups:
      description: Security groups
      returned: always
      sample:
      - name: default
      type: list
    status:
      description: VM status
      returned: always
      sample: ACTIVE
      type: str
    task_id:
      description: Active task. If None, action has been performed immediately in
        the request itself
      returned: always
      sample: f28a4982-9be1-4e50-84e7-6d1a6d3f8a02
      type: str
    task_state:
      description: Task state
      returned: always
      sample: None
      type: str
    vm_state:
      description: Virtual machine state
      returned: always
      sample: active
      type: str
    volumes:
      description: List of volumes
      returned: always
      sample:
      - delete_on_termination: false
        id: 28bfe198-a003-4283-8dca-ab5da4a71b62
      type: dict
  description:
  - Response depends of I(command).
  - Resource dictionary.
  returned: always
  type: complex

See also