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.
This commit is contained in:
netservers 2017-06-13 06:30:59 +01:00 committed by René Moser
parent eb7530df95
commit d5becd728e

View file

@ -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),