# Copy a template file to a destination other than inventory .

**URL:** <https://forum.ansible.com/t/copy-a-template-file-to-a-destination-other-than-inventory/24847>\
**Category:** Ansible Project\
**Created:** [June 29, 2017, 9:51am UTC](https://forum.ansible.com/t/copy-a-template-file-to-a-destination-other-than-inventory/24847 "2017-06-29T09:51:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ray\_Cromwell](https://avatars.discourse-cdn.com/v4/letter/r/5fc32e/32.png) [@Ray\_Cromwell](https://forum.ansible.com/u/Ray_Cromwell)\
**Post date:** [June 29, 2017, 9:51am UTC](https://forum.ansible.com/t/copy-a-template-file-to-a-destination-other-than-inventory/24847/1 "2017-06-29T09:51:26Z")

</div>

Hi .  
I have a playbook for icinga which applies the nrpe config to a list of hosts in inventory file .  
The problem I have is that within the same playbook I have another role which needs to copy host specific config to an icinga server in different environments.

I can use a template

e.g.

- name: copy host script  
template:  
src: hostname.j2  
dest: /home/rcromwell/{{ ansible\_hostname }}.{{ansible\_domain}}

But the the “dest:” needs to be the the icinga server . Not the client . Is there a way to achieve this ?  
Here is an example what I am trying achieve using set\_facts …

e.g.

- include: set\_facts.yml

- name: ‘dev’  
set\_fact:  
ic2host: [ic2.dev.yoo.com](http://ic2.dev.yoo.com)  
when: \>  
ansible\_env == “[dev.yoo.com](http://dev.yoo.com)”

- name: ‘dev2’  
set\_fact:  
ic2host: [ic2.dev2.yoo.com](http://ic2.dev2.yoo.com)  
when: \>  
ansible\_env == “[dev2.yoo.com](http://dev2.yoo.com)”

- name: copy host script  
template:  
src: hostname.j2  
dest: {{ ic2host }}/home/rcromwell/{{ ansible\_hostname }}.{{ansible\_domain}}

Any hel would be appreciated … //

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [June 29, 2017, 5:45pm UTC](https://forum.ansible.com/t/copy-a-template-file-to-a-destination-other-than-inventory/24847/2 "2017-06-29T17:45:18Z")

</div>

Use delegate\_to: \<name of icinga server\>

- name: copy host script  
&nbsp;&nbsp;&nbsp;template:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src: hostname.j2  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: /home/rcromwell/{{ ansible\_hostname }}.{{ansible\_domain}}  
&nbsp;&nbsp;&nbsp;delegate\_to: icinga-server
