# Push multiple configuration files to multiple servers

**URL:** <https://forum.ansible.com/t/push-multiple-configuration-files-to-multiple-servers/13858>\
**Category:** Ansible Project\
**Created:** [November 6, 2013, 9:20pm UTC](https://forum.ansible.com/t/push-multiple-configuration-files-to-multiple-servers/13858 "2013-11-06T21:20:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mtovey](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@mtovey](https://forum.ansible.com/u/mtovey)\
**Post date:** [November 6, 2013, 9:20pm UTC](https://forum.ansible.com/t/push-multiple-configuration-files-to-multiple-servers/13858/1 "2013-11-06T21:20:17Z")

</div>

I am trying to figure out a method of pushing configuration files to groups of servers. The requirement is that all servers receive file1, most servers receive file2, some servers receive file3, other servers receive file4, and so on. I am trying to use the ‘copy’ task for this, but I haven’t found a good method of looping over the file names.  
I have set up the inventory file with the servers in multiple groups based upon the files they need to receive:

[all\_servers]  
server1  
server2  
server3  
server4

[most\_servers]  
server1  
server3  
server4

[some\_servers]  
server1  
server3

[other\_servers]  
server2  
server4

Then in the group\_vars/groupname files, I have:

group\_vars/all  
config\_file: file1

group\_vars/most\_servers  
config\_file:file2

group\_vars/some\_servers  
config\_file:file3

group\_vars/other\_servers  
config\_file:file4

I am trying to find a way to loop through all of the groups that a server is a member of and collect the configuration file names. I have tried using with\_items and hostvars[inventory\_hostname].group\_names, but I haven’t found a way to extract the contents of config\_file for each of the groups. The only other way I can think of to do this is to put all of the configuration files names that are to be installed on a group of servers into that group’s group file:

group\_vars/some\_servers  
config\_file:

- file1
- file2
- file3

group\_vars/other\_servers  
config\_file:

- file1
- file4

This works, but it means that I have to make sure that all of the group files are updated together each time we make a change to the configuration file list instead of making the change to just one file. The former can present a greater chance of introducing errors because a group file might be missed, there are more places where typos can be introduced, etc.  
So, is there a way to loop through the groups that a server is a member of?  
Thanks,  
-Mark

---

<div class="post-metadata">

**Author:** ![Gonzalo\_Servat](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Gonzalo\_Servat](https://forum.ansible.com/u/Gonzalo_Servat)\
**Post date:** [November 6, 2013, 9:26pm UTC](https://forum.ansible.com/t/push-multiple-configuration-files-to-multiple-servers/13858/2 "2013-11-06T21:26:30Z")

</div>

If you have ever used Puppet, this would be doable with Hiera. Very keen to hear how this sort of thing is done in Ansible.

GS

---

<div class="post-metadata">

**Author:** ![mtovey](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@mtovey](https://forum.ansible.com/u/mtovey)\
**Post date:** [November 6, 2013, 10:28pm UTC](https://forum.ansible.com/t/push-multiple-configuration-files-to-multiple-servers/13858/3 "2013-11-06T22:28:35Z")

</div>

I am in Portland, OR, just a few blocks away from Puppet Labs. There is plenty of support for Puppet around here. But I like the Ansible model of using ssh and sudo better. That way I don’t have to install a client, another potential point of access to our servers, and it allows us to split out administrative roles to other groups; not everyone needs root access to perform a task. But not being able to iterate across multiple groups has been a major stumbling block for me. I figured out a way of doing that in templates because Jinja2 has better support for looping, but that means I am putting logic into the templates, something that purists consider to be a no-no. Frankly, IMHO there just needs to be better support for looping in playbooks. A real “for” statement would be very useful here. Better access to the group variables would be good too, something similar to the hostvars variable (groupvars[group\_name].variable).  
-Mark

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 10, 2013, 9:20pm UTC](https://forum.ansible.com/t/push-multiple-configuration-files-to-multiple-servers/13858/4 "2013-11-10T21:20:14Z")

</div>

- hosts: some\_servers  
tasks:
- template: src={{ item }} dest = {{ where\_to }}  
with\_items: some\_files

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 10, 2013, 9:21pm UTC](https://forum.ansible.com/t/push-multiple-configuration-files-to-multiple-servers/13858/5 "2013-11-10T21:21:35Z")

</div>

Happy to answer specific questions, but please avoid product comparisons so I can resist telling you what I think about them 🙂

" But not being able to iterate across multiple groups has been a major stumbling block for me. "

I’m not sure what this means, in particular. You can iterate across the members of groups, but I’d need to see a specific example of something you are trying to model.
