W3cubDocs

/Ansible

cs_instance - Manages instances and virtual machines on Apache CloudStack based clouds.

New in version 2.0.

Synopsis

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

Requirements (on host that executes module)

  • python >= 2.6
  • cs >= 0.6.10

Options

parameter required default choices comments
account
no
Account the instance is related to.
affinity_groups
no
Affinity groups names to be applied to the new instance.
aliases: affinity_group
api_http_method
no get
  • get
  • post
HTTP method used.
api_key
no
API key of the CloudStack API.
api_region
no cloudstack
Name of the ini section in the cloustack.ini file.
api_secret
no
Secret key of the CloudStack API.
api_timeout
no 10
HTTP timeout.
api_url
no
URL of the CloudStack API e.g. https://cloud.example.com/client/api.
cpu
no
The number of CPUs to allocate to the instance, used with custom service offerings
cpu_speed
no
The clock speed/shares allocated to the instance, used with custom service offerings
disk_offering
no
Name of the disk offering to be used.
disk_size
no
Disk size in GByte required if deploying instance from ISO.
display_name
no
Custom display name of the instances.
Display name will be set to name if not specified.
Either name or display_name is required.
domain
no
Domain the instance is related to.
force
no
Force stop/start the instance if required to apply changes, otherwise a running instance will not be changed.
group
no
Group in where the new instance should be in.
hypervisor
no
  • KVM
  • VMware
  • BareMetal
  • XenServer
  • LXC
  • HyperV
  • UCS
  • OVM
Name the hypervisor to be used for creating the new instance.
Relevant when using 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.
ip6_address
no
IPv6 address for default instance's network.
ip_address
no
IPv4 address for default instance's network during creation.
ip_to_networks
no
List of mappings in the form {'network': NetworkName, 'ip': 1.2.3.4}
Mutually exclusive with networks option.
aliases: ip_to_network
iso
no
Name or id of the ISO to be used for creating the new instance.
Required when using state=present.
Mutually exclusive with template option.
keyboard
no
  • de
  • de-ch
  • es
  • fi
  • fr
  • fr-be
  • fr-ch
  • is
  • it
  • jp
  • nl-be
  • no
  • pt
  • uk
  • us
Keyboard device type for the instance.
memory
no
The memory allocated to the instance, used with custom service offerings
name
no
Host name of the instance. name can only contain ASCII letters.
Name will be generated (UUID) by CloudStack if not specified and can not be changed afterwards.
Either name or display_name is required.
networks
no
List of networks to use for the new instance.
aliases: network
poll_async
no True
Poll async jobs until job has finished.
project
no
Name of the project the instance to be deployed in.
root_disk_size
no
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)
security_groups
no
List of security groups the instance to be applied to.
aliases: security_group
service_offering
no
Name or id of the service offering of the new instance.
If not set, first found service offering is used.
ssh_key
no
Name of the SSH key to be deployed on the new instance.
state
no present
  • deployed
  • started
  • stopped
  • restarted
  • restored
  • destroyed
  • expunged
  • present
  • absent
State of the instance.
tags
no
List of tags. Tags are a list of dictionaries having keys key and value.
If you want to delete all tags, set a empty list e.g. tags: [].
aliases: tag
template
no
Name or id of the template to be used for creating the new instance.
Required when using state=present.
Mutually exclusive with ISO option.
template_filter
(added in 2.1)
no executable
  • featured
  • self
  • selfexecutable
  • sharedexecutable
  • executable
  • community
Name of the filter used to search for the template or iso.
Used for params iso or template on state=present.
aliases: iso_filter
user_data
no
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 CLOUDSTACK_METHOD=post to increase the HTTP_GET size limit of 2KB to 32 KB.
zone
no
Name of the zone in which the instance should be deployed.
If not set, default zone is used.

Examples

# Create a instance from an ISO
# NOTE: Names of offerings and ISOs depending on the CloudStack configuration.
- 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

# 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

# Create or update a instance on Exoscale's public cloud using display_name.
# Note: user_data can be used to kickstart the instance using cloud-init yaml config.
- cs_instance:
    display_name: web-vm-1
    template: Linux Debian 7 64-bit
    service_offering: Tiny
    ssh_key: [email protected]
    tags:
      - key: admin
        value: john
      - key: foo
        value: bar
    user_data: |
        #cloud-config
        packages:
          - nginx
  delegate_to: localhost

# 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

# Ensure an instance is stopped
- cs_instance:
    name: web-vm-1
    state: stopped
  delegate_to: localhost

# Ensure an instance is running
- cs_instance:
    name: web-vm-1
    state: started
  delegate_to: localhost

# Remove an instance
- cs_instance:
    name: web-vm-1
    state: absent
  delegate_to: localhost

Return Values

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

name description returned type sample
domain
Domain the instance is related to.
success string example domain
tags
List of resource tags associated with the instance.
success dict [ { "key": "foo", "value": "bar" } ]
ssh_key
Name of SSH key deployed to instance.
success string key@work
public_ip
Public IP address with instance via static NAT rule.
success string 1.2.3.4
display_name
Display name of the instance.
success string web-01
service_offering
Name of the service offering the instance has.
success string 2cpu_2gb
password
The password of the instance if exists.
success string Ge2oe7Do
id
UUID of the instance.
success string 04589590-ac63-4ffc-93f5-b698b8ac38b6
security_groups
Security groups the instance is in.
success list [ "default" ]
name
Name of the instance.
success string web-01
project
Name of project the instance is related to.
success string Production
account
Account the instance is related to.
success string example account
group
Group name of the instance is related.
success string web
password_enabled
True if password setting is enabled.
success boolean True
zone
Name of zone the instance is in.
success string ch-gva-2
created
Date of the instance was created.
success string 2014-12-01T14:57:57+0100
hypervisor
Hypervisor related to this instance.
success string KVM
default_ip
Default IP address of the instance.
success string 10.23.37.42
instance_name
Internal name of the instance (ROOT admin only).
success string i-44-3992-VM
state
State of the instance.
success string Running
iso
Name of ISO the instance was deployed with.
success string Debian-8-64bit
template
Name of template the instance was deployed with.
success string Debian-8-64bit
affinity_groups
Affinity groups the instance is in.
success list [ "webservers" ]

Notes

Note

  • Ansible uses the cs library’s configuration method if credentials are not provided by the arguments api_url, api_key, api_secret. Configuration is read from several locations, in the following order. - The CLOUDSTACK_ENDPOINT, CLOUDSTACK_KEY, CLOUDSTACK_SECRET and CLOUDSTACK_METHOD. CLOUDSTACK_TIMEOUT environment variables. - A CLOUDSTACK_CONFIG environment variable pointing to an .ini file, - A cloudstack.ini file in the current working directory. - A .cloudstack.ini file in the users home directory. Optionally multiple credentials and endpoints can be specified using ini sections in cloudstack.ini. Use the argument api_region to select the section name, default section is cloudstack. See https://github.com/exoscale/cs for more information.
  • A detailed guide about cloudstack modules can be found on http://docs.ansible.com/ansible/guide_cloudstack.html
  • This module supports check mode.

Status

This module is flagged as stableinterface which means that the maintainers for this module guarantee that no backward incompatible interface changes will be made.

For help in developing on modules, should you be so inclined, please read Community Information & Contributing, Testing Ansible and Developing Modules.

© 2012–2017 Michael DeHaan
© 2017 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/cs_instance_module.html