From d5becd728e8437acb79bab3350d4443a4a63b086 Mon Sep 17 00:00:00 2001 From: netservers Date: Tue, 13 Jun 2017 06:30:59 +0100 Subject: [PATCH] Have cs_host search both name and ipaddress fields when fetching the host from listHosts. (#25628) Make ip_address an alias of name to allow playbooks to more clearly make use of IP addreses. --- lib/ansible/modules/cloud/cloudstack/cs_host.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/ansible/modules/cloud/cloudstack/cs_host.py b/lib/ansible/modules/cloud/cloudstack/cs_host.py index 2086a131f28..54d21242ea4 100644 --- a/lib/ansible/modules/cloud/cloudstack/cs_host.py +++ b/lib/ansible/modules/cloud/cloudstack/cs_host.py @@ -36,7 +36,7 @@ options: description: - Name of the host. required: true - aliases: [ 'url' ] + aliases: [ 'url', 'ip_address' ] username: description: - Username for the host. @@ -428,13 +428,15 @@ class AnsibleCloudStackHost(AnsibleCloudStack): def get_host(self): host = None + name = self.module.params.get('name') args = { 'zoneid': self.get_zone(key='id'), - 'name': self.module.params.get('name'), } - hosts = self.cs.listHosts(**args) - if hosts: - host = hosts['host'][0] + res = self.cs.listHosts(**args) + if res: + for h in res['host']: + if name in [h['ipaddress'], h['name']]: + host = h return host def present_host(self): @@ -506,7 +508,7 @@ class AnsibleCloudStackHost(AnsibleCloudStack): def main(): argument_spec = cs_argument_spec() argument_spec.update(dict( - name=dict(required=True, aliases=['url']), + name=dict(required=True, aliases=['url', 'ip_address']), password=dict(default=None, no_log=True), username=dict(default=None), hypervisor=dict(choices=CS_HYPERVISORS, default=None),