# How to distribute file per server?

**URL:** <https://forum.ansible.com/t/how-to-distribute-file-per-server/20078>\
**Category:** Ansible Project\
**Created:** [December 27, 2015, 7:34pm UTC](https://forum.ansible.com/t/how-to-distribute-file-per-server/20078 "2015-12-27T19:34:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jakov\_Sosic](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@Jakov\_Sosic](https://forum.ansible.com/u/Jakov_Sosic)\
**Post date:** [December 27, 2015, 7:34pm UTC](https://forum.ansible.com/t/how-to-distribute-file-per-server/20078/1 "2015-12-27T19:34:10Z")

</div>

Hi guys,

sorry if this is a newbie question, but looking around I couldn't find an answer...

I have my own CA, and create x509 key and certificate for each server.

What is the best way to distribute them with ansible? Currently, they are distributed via host\_vars, and certificate contents i pasted within variable. That seems to me like a cludgy solution, I would like to rather have files within repository, then c/p within host\_vars/group\_vars.

These files are pure text by chance, what would happen if I wanted to distribute for example java keystore files via Ansible?

How do you do it?

What I've come up so far is role called 'ca', which has structure looking like this:

% find roles/ca/files  
roles/ca/files  
roles/ca/files/ca.crt.pem  
roles/ca/files/private  
roles/ca/files/private/myhost1.example.net.crt.pem  
roles/ca/files/certs  
roles/ca/files/certs/myhost1.example.net.key.pem  
roles/ca/files/keystore  
roles/ca/files/keystore/myhost1.example.net.ks

Then, I just use copy with {{ ansible\_nodename }} to push files around...

Any smarter solutions for this problem?

---

<div class="post-metadata">

**Author:** ![Jakov\_Sosic](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@Jakov\_Sosic](https://forum.ansible.com/u/Jakov_Sosic)\
**Post date:** [January 9, 2016, 7:29pm UTC](https://forum.ansible.com/t/how-to-distribute-file-per-server/20078/2 "2016-01-09T19:29:15Z")

</div>

Anyone?!?!

---

<div class="post-metadata">

**Author:** ![Raghu\_Udiyar](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@Raghu\_Udiyar](https://forum.ansible.com/u/Raghu_Udiyar)\
**Post date:** [January 11, 2016, 6:57pm UTC](https://forum.ansible.com/t/how-to-distribute-file-per-server/20078/3 "2016-01-11T18:57:40Z")

</div>

Use inventory\_hostname and with\_fileglob ([https://docs.ansible.com/ansible/playbooks\_loops.html#id4](https://docs.ansible.com/ansible/playbooks_loops.html#id4)) to match the filenames, and use the file module to copy the respective files.

Something like :

`

- file: src={{item|basename}}.crt.pem dest=/etc/ssl/certs/{{item|basename}}.crt.pem owner=root group=root mode=0644  
with\_fileglob:
- …/files/\*.crt.pem  
when: item|basename == inventory\_hostname  
`
