From 1a7b9090df514206d87508be598179bb2ef9e360 Mon Sep 17 00:00:00 2001 From: Fabio Alessandro Locati Date: Thu, 1 Dec 2016 16:40:49 +0000 Subject: [PATCH] Native YAML - cloud/cloudstack (#3613) --- .../extras/cloud/cloudstack/cs_instance.py | 43 ++++++++++++------- .../cloud/cloudstack/cs_instance_facts.py | 7 +-- .../extras/cloud/cloudstack/cs_sshkeypair.py | 17 ++++++-- .../extras/cloud/cloudstack/cs_zone_facts.py | 7 +-- 4 files changed, 49 insertions(+), 25 deletions(-) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_instance.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_instance.py index 9d3a2c025af..127bd7ed8dc 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_instance.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_instance.py @@ -223,8 +223,7 @@ extends_documentation_fragment: cloudstack EXAMPLES = ''' # Create a instance from an ISO # NOTE: Names of offerings and ISOs depending on the CloudStack configuration. -- local_action: - module: cs_instance +- cs_instance: name: web-vm-1 iso: Linux Debian 7 64-bit hypervisor: VMware @@ -237,50 +236,64 @@ EXAMPLES = ''' - Server Integration - Sync Integration - Storage Integration + delegate_to: localhost # For changing a running instance, use the 'force' parameter -- local_action: - module: cs_instance +- 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. -- local_action: - module: cs_instance +- 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 } + - 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 -- local_action: - module: cs_instance +- 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.168.1.1'} + - network: NetworkA + ip: 10.1.1.1 + - network: NetworkB + ip: 192.0.2.1 + delegate_to: localhost # Ensure an instance is stopped -- local_action: cs_instance name=web-vm-1 state=stopped +- cs_instance: + name: web-vm-1 + state: stopped + delegate_to: localhost # Ensure an instance is running -- local_action: cs_instance name=web-vm-1 state=started +- cs_instance: + name: web-vm-1 + state: started + delegate_to: localhost # Remove an instance -- local_action: cs_instance name=web-vm-1 state=absent +- cs_instance: + name: web-vm-1 + state: absent + delegate_to: localhost ''' RETURN = ''' diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_instance_facts.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_instance_facts.py index f405debca3f..4efaf645291 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_instance_facts.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_instance_facts.py @@ -50,11 +50,12 @@ extends_documentation_fragment: cloudstack ''' EXAMPLES = ''' -- local_action: - module: cs_instance_facts +- cs_instance_facts: name: web-vm-1 + delegate_to: localhost -- debug: var=cloudstack_instance +- debug: + var: cloudstack_instance ''' RETURN = ''' diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_sshkeypair.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_sshkeypair.py index 182c00f762d..159f39bb00d 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_sshkeypair.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_sshkeypair.py @@ -64,15 +64,24 @@ extends_documentation_fragment: cloudstack EXAMPLES = ''' # create a new private / public key pair: -- local_action: cs_sshkeypair name=linus@example.com +- cs_sshkeypair: + name: linus@example.com + delegate_to: localhost register: key -- debug: msg='private key is {{ key.private_key }}' +- debug: + msg: 'Private key is {{ key.private_key }}' # remove a public key by its name: -- local_action: cs_sshkeypair name=linus@example.com state=absent +- cs_sshkeypair: + name: linus@example.com + state: absent + delegate_to: localhost # register your existing local public key: -- local_action: cs_sshkeypair name=linus@example.com public_key='{{ lookup('file', '~/.ssh/id_rsa.pub') }}' +- cs_sshkeypair: + name: linus@example.com + public_key: '{{ lookup('file', '~/.ssh/id_rsa.pub') }}' + delegate_to: localhost ''' RETURN = ''' diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_zone_facts.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_zone_facts.py index 7b5076659fd..2ce82423ec6 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_zone_facts.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_zone_facts.py @@ -35,11 +35,12 @@ extends_documentation_fragment: cloudstack ''' EXAMPLES = ''' -- local_action: - module: cs_zone_facts +- cs_zone_facts: name: ch-gva-1 + delegate_to: localhost -- debug: var=cloudstack_zone +- debug: + var: cloudstack_zone ''' RETURN = '''