# ansible script to do remote execution of templates

**URL:** <https://forum.ansible.com/t/ansible-script-to-do-remote-execution-of-templates/30137>\
**Category:** Ansible Project\
**Created:** [April 17, 2019, 3:55pm UTC](https://forum.ansible.com/t/ansible-script-to-do-remote-execution-of-templates/30137 "2019-04-17T15:55:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rashmi\_nair](https://avatars.discourse-cdn.com/v4/letter/r/8e7dd6/32.png) [@rashmi\_nair](https://forum.ansible.com/u/rashmi_nair)\
**Post date:** [April 17, 2019, 3:55pm UTC](https://forum.ansible.com/t/ansible-script-to-do-remote-execution-of-templates/30137/1 "2019-04-17T15:55:58Z")

</div>

Hi All,

I have a scenario where I need to execute ansible script which will run the templates on remote server. I have list of remote servers which when given to delegate\_to is not working and fileglob is not copying the files to /tmp/copy rather folder creating a copy file.

Please help

- hosts: 127.0.0.1  
connection: local  
tasks:

- name: Install dependencies  
yum: name={{ item }} state=present  
with\_items:

- htop

- git.x86\_64

- python-devel

- name: Clone ansible repo on remote server  
git: repo=ssh://git@\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\***.git  
dest=/tmp  
version=feature/**  
accept\_hostkey=yes  
delegate\_to: host1

- name: Install config  
template:  
src: “{{ item }}”  
dest: “/tmp/copy”  
with\_fileglob: “\*”  
delegate\_to: host1

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [April 18, 2019, 3:58pm UTC](https://forum.ansible.com/t/ansible-script-to-do-remote-execution-of-templates/30137/2 "2019-04-18T15:58:10Z")

</div>

The fileglob lookup, like ALL lookups  
([https://docs.ansible.com/ansible/latest/plugins/lookup.html#lookup-plugins](https://docs.ansible.com/ansible/latest/plugins/lookup.html#lookup-plugins)),  
always runs on the controller

The template action plugin can ONLY use as source files on the  
controller. [https://docs.ansible.com/ansible/latest/modules/template\_module.html#template-module](https://docs.ansible.com/ansible/latest/modules/template_module.html#template-module)  
(see src option)

You either need to rung the git action with `delegate\_to: localhost'  
or syncronize the files from the remote before executing the template  
action.
