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:
parent
eb7530df95
commit
d5becd728e
1 changed files with 8 additions and 6 deletions
|
@ -36,7 +36,7 @@ options:
|
||||||
description:
|
description:
|
||||||
- Name of the host.
|
- Name of the host.
|
||||||
required: true
|
required: true
|
||||||
aliases: [ 'url' ]
|
aliases: [ 'url', 'ip_address' ]
|
||||||
username:
|
username:
|
||||||
description:
|
description:
|
||||||
- Username for the host.
|
- Username for the host.
|
||||||
|
@ -428,13 +428,15 @@ class AnsibleCloudStackHost(AnsibleCloudStack):
|
||||||
|
|
||||||
def get_host(self):
|
def get_host(self):
|
||||||
host = None
|
host = None
|
||||||
|
name = self.module.params.get('name')
|
||||||
args = {
|
args = {
|
||||||
'zoneid': self.get_zone(key='id'),
|
'zoneid': self.get_zone(key='id'),
|
||||||
'name': self.module.params.get('name'),
|
|
||||||
}
|
}
|
||||||
hosts = self.cs.listHosts(**args)
|
res = self.cs.listHosts(**args)
|
||||||
if hosts:
|
if res:
|
||||||
host = hosts['host'][0]
|
for h in res['host']:
|
||||||
|
if name in [h['ipaddress'], h['name']]:
|
||||||
|
host = h
|
||||||
return host
|
return host
|
||||||
|
|
||||||
def present_host(self):
|
def present_host(self):
|
||||||
|
@ -506,7 +508,7 @@ class AnsibleCloudStackHost(AnsibleCloudStack):
|
||||||
def main():
|
def main():
|
||||||
argument_spec = cs_argument_spec()
|
argument_spec = cs_argument_spec()
|
||||||
argument_spec.update(dict(
|
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),
|
password=dict(default=None, no_log=True),
|
||||||
username=dict(default=None),
|
username=dict(default=None),
|
||||||
hypervisor=dict(choices=CS_HYPERVISORS, default=None),
|
hypervisor=dict(choices=CS_HYPERVISORS, default=None),
|
||||||
|
|
Loading…
Reference in a new issue