For consistency, add host should take a key named 'name' in addition to 'hostname'.

pull/2117/head
Michael DeHaan 12 years ago
parent cc9bc91a6c
commit ab389d8908

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

@ -9,9 +9,9 @@ description:
Takes variables so you can define the new hosts more fully.
version_added: 0.9
options:
hostname:
name:
description:
- The hostname/ip of the host to add to the inventory
- The hostname/ip of the host to add to the inventory, can include a colon and a port number.
required: true
groups:
aliases: [ 'groupname' ]

Loading…
Cancel
Save