community.general.cs_instance (0.1.1) — module

Manages instances and virtual machines on Apache CloudStack based clouds.

Authors: René Moser (@resmo)

stableinterface | supported by community

Install collection

Install with ansible-galaxy collection install community.general:==0.1.1


Add to requirements.yml

  collections:
    - name: community.general
      version: 0.1.1

Description

Deploy, start, update, scale, restart, restore, stop and destroy instances.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# NOTE: Names of offerings and ISOs depending on the CloudStack configuration.
- name: create a instance from an ISO
  cs_instance:
    name: web-vm-1
    iso: Linux Debian 7 64-bit
    hypervisor: VMware
    project: Integration
    zone: ch-zrh-ix-01
    service_offering: 1cpu_1gb
    disk_offering: PerfPlus Storage
    disk_size: 20
    networks:
      - Server Integration
      - Sync Integration
      - Storage Integration
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: for changing a running instance, use the 'force' parameter
  cs_instance:
    name: web-vm-1
    display_name: web-vm-01.example.com
    iso: Linux Debian 7 64-bit
    service_offering: 2cpu_2gb
    force: yes
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# NOTE: user_data can be used to kickstart the instance using cloud-init yaml config.
- name: create or update a instance on Exoscale's public cloud using display_name.
  cs_instance:
    display_name: web-vm-1
    template: Linux Debian 7 64-bit
    service_offering: Tiny
    ssh_key: john@example.com
    tags:
      - key: admin
        value: john
      - key: foo
        value: bar
    user_data: |
        #cloud-config
        packages:
          - nginx
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: create an instance with multiple interfaces specifying the IP addresses
  cs_instance:
    name: web-vm-1
    template: Linux Debian 7 64-bit
    service_offering: Tiny
    ip_to_networks:
      - network: NetworkA
        ip: 10.1.1.1
      - network: NetworkB
        ip: 192.0.2.1
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: ensure an instance is stopped
  cs_instance:
    name: web-vm-1
    state: stopped
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: ensure an instance is running
  cs_instance:
    name: web-vm-1
    state: started
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: remove an instance
  cs_instance:
    name: web-vm-1
    state: absent
  delegate_to: localhost

Inputs

    
cpu:
    description:
    - The number of CPUs to allocate to the instance, used with custom service offerings
    type: int

iso:
    description:
    - Name or id of the ISO to be used for creating the new instance.
    - Required when using I(state=present).
    - Mutually exclusive with I(template) option.
    type: str

host:
    description:
    - Host on which an instance should be deployed or started on.
    - Only considered when I(state=started) or instance is running.
    - Requires root admin privileges.
    type: str

name:
    description:
    - Host name of the instance. C(name) can only contain ASCII letters.
    - Name will be generated (UUID) by CloudStack if not specified and can not be changed
      afterwards.
    - Either C(name) or C(display_name) is required.
    type: str

tags:
    aliases:
    - tag
    description:
    - List of tags. Tags are a list of dictionaries having keys C(key) and C(value).
    - 'If you want to delete all tags, set a empty list e.g. I(tags: []).'
    type: list

zone:
    description:
    - Name of the zone in which the instance should be deployed.
    - If not set, default zone is used.
    type: str

force:
    default: false
    description:
    - Force stop/start the instance if required to apply changes, otherwise a running
      instance will not be changed.
    type: bool

group:
    description:
    - Group in where the new instance should be in.
    type: str

state:
    choices:
    - deployed
    - started
    - stopped
    - restarted
    - restored
    - destroyed
    - expunged
    - present
    - absent
    default: present
    description:
    - State of the instance.
    type: str

domain:
    description:
    - Domain the instance is related to.
    type: str

memory:
    description:
    - The memory allocated to the instance, used with custom service offerings
    type: int

account:
    description:
    - Account the instance is related to.
    type: str

api_key:
    description:
    - API key of the CloudStack API.
    - If not given, the C(CLOUDSTACK_KEY) env variable is considered.
    - As the last option, the value is taken from the ini config file, also see the notes.
    type: str

api_url:
    description:
    - URL of the CloudStack API e.g. https://cloud.example.com/client/api.
    - If not given, the C(CLOUDSTACK_ENDPOINT) env variable is considered.
    - As the last option, the value is taken from the ini config file, also see the notes.
    type: str

details:
    description:
    - Map to specify custom parameters.
    type: dict

project:
    description:
    - Name of the project the instance to be deployed in.
    type: str

ssh_key:
    description:
    - Name of the SSH key to be deployed on the new instance.
    type: str

keyboard:
    choices:
    - de
    - de-ch
    - es
    - fi
    - fr
    - fr-be
    - fr-ch
    - is
    - it
    - jp
    - nl-be
    - 'no'
    - pt
    - uk
    - us
    description:
    - Keyboard device type for the instance.
    type: str

networks:
    aliases:
    - network
    description:
    - List of networks to use for the new instance.
    type: list

template:
    description:
    - Name, display text or id of the template to be used for creating the new instance.
    - Required when using I(state=present).
    - Mutually exclusive with I(iso) option.
    type: str

cpu_speed:
    description:
    - The clock speed/shares allocated to the instance, used with custom service offerings
    type: int

disk_size:
    description:
    - Disk size in GByte required if deploying instance from ISO.
    type: int

user_data:
    description:
    - Optional data (ASCII) that can be sent to the instance upon a successful deployment.
    - The data will be automatically base64 encoded.
    - Consider switching to HTTP_POST by using I(CLOUDSTACK_METHOD=post) to increase the
      HTTP_GET size limit of 2KB to 32 KB.
    type: str

api_region:
    default: cloudstack
    description:
    - Name of the ini section in the C(cloustack.ini) file.
    - If not given, the C(CLOUDSTACK_REGION) env variable is considered.
    type: str

api_secret:
    description:
    - Secret key of the CloudStack API.
    - If not set, the C(CLOUDSTACK_SECRET) env variable is considered.
    - As the last option, the value is taken from the ini config file, also see the notes.
    type: str

hypervisor:
    description:
    - Name the hypervisor to be used for creating the new instance.
    - Relevant when using I(state=present), but only considered if not set on ISO/template.
    - If not set or found on ISO/template, first found hypervisor will be used.
    - Possible values are C(KVM), C(VMware), C(BareMetal), C(XenServer), C(LXC), C(HyperV),
      C(UCS), C(OVM), C(Simulator).
    type: str

ip_address:
    description:
    - IPv4 address for default instance's network during creation.
    type: str

poll_async:
    default: true
    description:
    - Poll async jobs until job has finished.
    type: bool

api_timeout:
    description:
    - HTTP timeout in seconds.
    - If not given, the C(CLOUDSTACK_TIMEOUT) env variable is considered.
    - As the last option, the value is taken from the ini config file, also see the notes.
    - Fallback value is 10 seconds if not specified.
    type: int

ip6_address:
    description:
    - IPv6 address for default instance's network.
    type: str

display_name:
    description:
    - Custom display name of the instances.
    - Display name will be set to I(name) if not specified.
    - Either I(name) or I(display_name) is required.
    type: str

disk_offering:
    description:
    - Name of the disk offering to be used.
    type: str

ip_to_networks:
    aliases:
    - ip_to_network
    description:
    - 'List of mappings in the form I({''network'': NetworkName, ''ip'': 1.2.3.4})'
    - Mutually exclusive with I(networks) option.
    type: list

root_disk_size:
    description:
    - Root disk size in GByte required if deploying instance with KVM hypervisor and want
      resize the root disk size at startup (need CloudStack >= 4.4, cloud-initramfs-growroot
      installed and enabled in the template)
    type: int

affinity_groups:
    aliases:
    - affinity_group
    description:
    - Affinity groups names to be applied to the new instance.
    type: list

api_http_method:
    choices:
    - get
    - post
    description:
    - HTTP method used to query the API endpoint.
    - If not given, the C(CLOUDSTACK_METHOD) env variable is considered.
    - As the last option, the value is taken from the ini config file, also see the notes.
    - Fallback value is C(get) if not specified.
    type: str

security_groups:
    aliases:
    - security_group
    description:
    - List of security groups the instance to be applied to.
    type: list

template_filter:
    aliases:
    - iso_filter
    choices:
    - all
    - featured
    - self
    - selfexecutable
    - sharedexecutable
    - executable
    - community
    default: executable
    description:
    - Name of the filter used to search for the template or iso.
    - Used for params I(iso) or I(template) on I(state=present).
    - The filter C(all) was added in 2.6.
    type: str

service_offering:
    description:
    - Name or id of the service offering of the new instance.
    - If not set, first found service offering is used.
    type: str

allow_root_disk_shrink:
    default: false
    description:
    - Enables a volume shrinkage when the new size is smaller than the old one.
    type: bool

Outputs

account:
  description: Account the instance is related to.
  returned: success
  sample: example account
  type: str
affinity_groups:
  description: Affinity groups the instance is in.
  returned: success
  sample: '[ "webservers" ]'
  type: list
created:
  description: Date of the instance was created.
  returned: success
  sample: 2014-12-01T14:57:57+0100
  type: str
default_ip:
  description: Default IP address of the instance.
  returned: success
  sample: 10.23.37.42
  type: str
default_ip6:
  description: Default IPv6 address of the instance.
  returned: if available
  sample: 2a04:c43:c00:a07:4b4:beff:fe00:74
  type: str
  version_added: '2.6'
  version_added_collection: community.general
display_name:
  description: Display name of the instance.
  returned: success
  sample: web-01
  type: str
domain:
  description: Domain the instance is related to.
  returned: success
  sample: example domain
  type: str
group:
  description: Group name of the instance is related.
  returned: success
  sample: web
  type: str
host:
  description: Hostname of hypervisor an instance is running on.
  returned: success and instance is running
  sample: host-01.example.com
  type: str
  version_added: '2.6'
  version_added_collection: community.general
hypervisor:
  description: Hypervisor related to this instance.
  returned: success
  sample: KVM
  type: str
id:
  description: UUID of the instance.
  returned: success
  sample: 04589590-ac63-4ffc-93f5-b698b8ac38b6
  type: str
instance_name:
  description: Internal name of the instance (ROOT admin only).
  returned: success
  sample: i-44-3992-VM
  type: str
iso:
  description: Name of ISO the instance was deployed with.
  returned: if available
  sample: Debian-8-64bit
  type: str
name:
  description: Name of the instance.
  returned: success
  sample: web-01
  type: str
password:
  description: The password of the instance if exists.
  returned: if available
  sample: Ge2oe7Do
  type: str
password_enabled:
  description: True if password setting is enabled.
  returned: success
  sample: true
  type: bool
project:
  description: Name of project the instance is related to.
  returned: success
  sample: Production
  type: str
public_ip:
  description: Public IP address with instance via static NAT rule.
  returned: if available
  sample: 1.2.3.4
  type: str
security_groups:
  description: Security groups the instance is in.
  returned: success
  sample: '[ "default" ]'
  type: list
service_offering:
  description: Name of the service offering the instance has.
  returned: success
  sample: 2cpu_2gb
  type: str
ssh_key:
  description: Name of SSH key deployed to instance.
  returned: if available
  sample: key@work
  type: str
state:
  description: State of the instance.
  returned: success
  sample: Running
  type: str
tags:
  description: List of resource tags associated with the instance.
  returned: success
  sample: '[ { "key": "foo", "value": "bar" } ]'
  type: list
template:
  description: Name of template the instance was deployed with.
  returned: success
  sample: Linux Debian 9 64-bit
  type: str
template_display_text:
  description: Display text of template the instance was deployed with.
  returned: success
  sample: Linux Debian 9 64-bit 200G Disk (2017-10-08-622866)
  type: str
  version_added: '2.6'
  version_added_collection: community.general
user-data:
  description: Optional data sent to the instance.
  returned: success
  sample: VXNlciBkYXRhIGV4YW1wbGUK
  type: str
zone:
  description: Name of zone the instance is in.
  returned: success
  sample: ch-gva-2
  type: str