From ab389d8908aa7839bf065886518dcd3162e73484 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Sun, 17 Feb 2013 20:45:37 -0500 Subject: [PATCH] For consistency, add host should take a key named 'name' in addition to 'hostname'. --- lib/ansible/runner/action_plugins/add_host.py | 15 +++++++-------- library/add_host | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/ansible/runner/action_plugins/add_host.py b/lib/ansible/runner/action_plugins/add_host.py index 3f3a95a3f0..a599500061 100644 --- a/lib/ansible/runner/action_plugins/add_host.py +++ b/lib/ansible/runner/action_plugins/add_host.py @@ -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) diff --git a/library/add_host b/library/add_host index 04e9f938f0..4abae8fe47 100644 --- a/library/add_host +++ b/library/add_host @@ -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' ]