Allow add_host to add hosts to multiple groups, groups is now an alias for groupname.
This commit is contained in:
parent
cde233f93c
commit
b365e04616
3 changed files with 22 additions and 18 deletions
|
@ -45,6 +45,8 @@ Ansible Changes By Release
|
|||
* fixed ~ expansion for fileglob
|
||||
* can set ansible_ssh_user and ansible_ssh_pass in inventory variables
|
||||
* lookup plugin macros like $FILE and $ENV now work without returning arrays in variable definitions/playbooks
|
||||
* add_host module can set ports and other inventory variables
|
||||
* add_host module can add modules to multiple groups (groups=a,b,c), groups now alias for groupname
|
||||
|
||||
1.0 "Eruption" -- Feb 1 2013
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ class ActionModule(object):
|
|||
|
||||
# Add any variables to the new_host
|
||||
for k in args.keys():
|
||||
if k != 'hostname' and k != 'groupname':
|
||||
if not k in [ 'hostname', 'groupname', 'groups' ]:
|
||||
new_host.set_variable(k, args[k])
|
||||
|
||||
|
||||
|
@ -68,17 +68,18 @@ class ActionModule(object):
|
|||
allgroup = inventory.get_group('all')
|
||||
allgroup.add_host(new_host)
|
||||
result['changed'] = True
|
||||
|
||||
|
||||
groupnames = args.get('groupname', args.get('groups', ''))
|
||||
# add it to the group if that was specified
|
||||
if 'groupname' in args:
|
||||
if not inventory.get_group(args['groupname']):
|
||||
new_group = Group(args['groupname'])
|
||||
inventory.add_group(new_group)
|
||||
|
||||
ngobj = inventory.get_group(args['groupname'])
|
||||
ngobj.add_host(new_host)
|
||||
vv("created 'add_host' ActionModule: groupname=%s"%(args['groupname']))
|
||||
result['new_group'] = args['groupname']
|
||||
if groupnames != '':
|
||||
for group_name in groupnames.split(","):
|
||||
if not inventory.get_group(group_name):
|
||||
new_group = Group(group_name)
|
||||
inventory.add_group(new_group)
|
||||
grp = inventory.get_group(group_name)
|
||||
grp.add_host(new_host)
|
||||
vv("added host to group via add_host module: %s" % group_name)
|
||||
result['new_groups'] = groupnames.split(",")
|
||||
|
||||
result['new_host'] = args['hostname']
|
||||
|
||||
|
|
|
@ -13,14 +13,15 @@ options:
|
|||
description:
|
||||
- The hostname/ip of the host to add to the inventory
|
||||
required: true
|
||||
groupname:
|
||||
groups:
|
||||
aliases: [ 'groupname' ]
|
||||
description:
|
||||
- The groupname to add the hostname to.
|
||||
- The groups to add the hostname to, comma seperated.
|
||||
required: false
|
||||
author: Seth Vidal
|
||||
examples:
|
||||
- description: add host to group 'just_created'
|
||||
code: add_host hostname=${ip_from_ec2create} groupname=just_created
|
||||
- description add a host with a non-standard port local to your machines
|
||||
code: add_host hostname='${new_ip}:${new_port}' ansible_ssh_port='${new_port}' ansible_ssh_host='${new_ip}' groupname=cloud_hosts
|
||||
'''
|
||||
- description: add host to group 'just_created' with variable foo=42
|
||||
code: add_host hostname=${ip_from_ec2create} groups=just_created foo=42
|
||||
- description: add a host with a non-standard port local to your machines
|
||||
code: add_host hostname='${new_ip}:${new_port}'
|
||||
'''
|
||||
|
|
Loading…
Reference in a new issue