summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRene Moser <mail@renemoser.net>2015-12-20 22:18:30 +0100
committerToshio Kuratomi <toshio@fedoraproject.org>2015-12-23 13:29:27 -0800
commitc731eac27193b7973653f9a865c3eb0110f1b211 (patch)
tree5cd6410c6d4929847b73feadead98fe69b9adf26
parent1e4cad1d0f303d2ae7b5641895a6fa3f3c224238 (diff)
downloadansible-modules-extras-c731eac27193b7973653f9a865c3eb0110f1b211.tar.gz
cloudstack: cs_instance: fix do not require name to be set to avoid clashes
Require one of display_name or name. If both is given, name is used as identifier.
-rw-r--r--cloud/cloudstack/cs_instance.py23
1 files changed, 18 insertions, 5 deletions
diff --git a/cloud/cloudstack/cs_instance.py b/cloud/cloudstack/cs_instance.py
index 88076fa1..7b1eeafd 100644
--- a/cloud/cloudstack/cs_instance.py
+++ b/cloud/cloudstack/cs_instance.py
@@ -30,10 +30,15 @@ options:
name:
description:
- Host name of the instance. C(name) can only contain ASCII letters.
- required: true
+ - 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.
+ required: false
+ default: null
display_name:
description:
- Custom display name of the instances.
+ - Display name will be set to C(name) if not specified.
+ - Either C(name) or C(display_name) is required.
required: false
default: null
group:
@@ -225,16 +230,21 @@ EXAMPLES = '''
service_offering: 2cpu_2gb
force: yes
-# Create or update a instance on Exoscale's public cloud
+# 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
- name: web-vm-1
+ 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
# Create an instance with multiple interfaces specifying the IP addresses
- local_action:
@@ -479,7 +489,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
def get_instance(self):
instance = self.instance
if not instance:
- instance_name = self.module.params.get('name')
+ instance_name = self.get_or_fallback('name', 'display_name')
args = {}
args['account'] = self.get_account(key='name')
@@ -865,7 +875,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
def main():
argument_spec = cs_argument_spec()
argument_spec.update(dict(
- name = dict(required=True),
+ name = dict(default=None),
display_name = dict(default=None),
group = dict(default=None),
state = dict(choices=['present', 'deployed', 'started', 'stopped', 'restarted', 'restored', 'absent', 'destroyed', 'expunged'], default='present'),
@@ -905,6 +915,9 @@ def main():
module = AnsibleModule(
argument_spec=argument_spec,
required_together=required_together,
+ required_one_of = (
+ ['display_name', 'name'],
+ ),
mutually_exclusive = (
['template', 'iso'],
),