mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 05:10:22 -07:00
For consistency, add host should take a key named 'name' in addition to 'hostname'.
This commit is contained in:
parent
cc9bc91a6c
commit
ab389d8908
2 changed files with 9 additions and 10 deletions
|
@ -40,16 +40,15 @@ class ActionModule(object):
|
|||
return ReturnData(conn=conn, comm_ok=True, result=dict(skipped=True, msg='check mode not supported for this module'))
|
||||
|
||||
args = parse_kv(module_args)
|
||||
if not 'hostname' in args:
|
||||
raise ae("'hostname' is a required argument.")
|
||||
|
||||
vv("created 'add_host' ActionModule: hostname=%s"%(args['hostname']))
|
||||
|
||||
if not 'hostname' in args and not 'name' in args:
|
||||
raise ae("'name' is a required argument.")
|
||||
|
||||
result = {'changed': True}
|
||||
|
||||
# Parse out any hostname:port patterns
|
||||
new_hostname = args['hostname']
|
||||
new_hostname = args.get('hostname', args.get('name', None))
|
||||
vv("creating host via 'add_host': hostname=%s" % new_hostname)
|
||||
|
||||
if ":" in new_hostname:
|
||||
new_hostname, new_port = new_hostname.split(":")
|
||||
args['ansible_ssh_port'] = new_port
|
||||
|
@ -60,7 +59,7 @@ class ActionModule(object):
|
|||
|
||||
# Add any variables to the new_host
|
||||
for k in args.keys():
|
||||
if not k in [ 'hostname', 'groupname', 'groups' ]:
|
||||
if not k in [ 'name', 'hostname', 'groupname', 'groups' ]:
|
||||
new_host.set_variable(k, args[k])
|
||||
|
||||
|
||||
|
@ -81,7 +80,7 @@ class ActionModule(object):
|
|||
vv("added host to group via add_host module: %s" % group_name)
|
||||
result['new_groups'] = groupnames.split(",")
|
||||
|
||||
result['new_host'] = args['hostname']
|
||||
result['new_host'] = new_hostname
|
||||
|
||||
return ReturnData(conn=conn, comm_ok=True, result=result)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue