1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Allow add_host to add hosts to multiple groups, groups is now an alias for groupname.

This commit is contained in:
Michael DeHaan 2013-02-17 11:22:50 -05:00
parent cde233f93c
commit b365e04616
3 changed files with 22 additions and 18 deletions

View file

@ -45,6 +45,8 @@ Ansible Changes By Release
* fixed ~ expansion for fileglob * fixed ~ expansion for fileglob
* can set ansible_ssh_user and ansible_ssh_pass in inventory variables * 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 * 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 1.0 "Eruption" -- Feb 1 2013

View file

@ -60,7 +60,7 @@ class ActionModule(object):
# Add any variables to the new_host # Add any variables to the new_host
for k in args.keys(): 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]) new_host.set_variable(k, args[k])
@ -68,17 +68,18 @@ class ActionModule(object):
allgroup = inventory.get_group('all') allgroup = inventory.get_group('all')
allgroup.add_host(new_host) allgroup.add_host(new_host)
result['changed'] = True result['changed'] = True
groupnames = args.get('groupname', args.get('groups', ''))
# add it to the group if that was specified # add it to the group if that was specified
if 'groupname' in args: if groupnames != '':
if not inventory.get_group(args['groupname']): for group_name in groupnames.split(","):
new_group = Group(args['groupname']) if not inventory.get_group(group_name):
inventory.add_group(new_group) new_group = Group(group_name)
inventory.add_group(new_group)
ngobj = inventory.get_group(args['groupname']) grp = inventory.get_group(group_name)
ngobj.add_host(new_host) grp.add_host(new_host)
vv("created 'add_host' ActionModule: groupname=%s"%(args['groupname'])) vv("added host to group via add_host module: %s" % group_name)
result['new_group'] = args['groupname'] result['new_groups'] = groupnames.split(",")
result['new_host'] = args['hostname'] result['new_host'] = args['hostname']

View file

@ -13,14 +13,15 @@ options:
description: description:
- The hostname/ip of the host to add to the inventory - The hostname/ip of the host to add to the inventory
required: true required: true
groupname: groups:
aliases: [ 'groupname' ]
description: description:
- The groupname to add the hostname to. - The groups to add the hostname to, comma seperated.
required: false required: false
author: Seth Vidal author: Seth Vidal
examples: examples:
- description: add host to group 'just_created' - description: add host to group 'just_created' with variable foo=42
code: add_host hostname=${ip_from_ec2create} groupname=just_created 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 - 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 code: add_host hostname='${new_ip}:${new_port}'
''' '''