delegate_to, templates and roles. Files are not being created in /tmp

68 views
Skip to first unread message

Chethan S

unread,
Sep 28, 2016, 7:15:27 AM9/28/16
to Ansible Project
I have an Ansible role (resides in ../roles/rolename/tasks) which goes like this - 

- name: Creating the PowerShell Scripts necessary
 
template: src=script.ps1 dest=/tmp/{{item}}.ps1
  with_items
: "{{ names }}"
  delegate_to
: localhost

The script.ps1 shown under src resides in ../roles/rolename/templates/. After running the playbook if I check the Ansible Controller VMs /tmp folder, I don't see the files that are supposed to be created. The names are machine1, machine2 etc. I have tried changing localhost to 127.0.0.1 but that didn't help me.

The debug log reports success - 

changed: [machine1 -> localhost] => (item=machine1) => {"changed": true, ......"dest": "/tmp/machine1.ps1"....}
changed
: [machine2 -> localhost] => (item=machine1) => {"changed": true, ......"dest": "/tmp/machine2.ps1"....}

Actually, the next step in my role is expected to copy the files generated in /tmp/ to a specified location in machine1, machine2 etc.

What is wrong in my way of doing things?


Kai Stian Olstad

unread,
Sep 28, 2016, 10:07:57 AM9/28/16
to ansible...@googlegroups.com
On 28. sep. 2016 13:15, Chethan S wrote:
> I have an Ansible role (resides in ../roles/rolename/tasks) which goes like
> this -
>
> - name: Creating the PowerShell Scripts necessary
> template: src=script.ps1 dest=/tmp/{{item}}.ps1
> with_items: "{{ names }}"
> delegate_to: localhost
>
> The script.ps1 shown under src resides in ../roles/rolename/templates/.
> After running the playbook if I check the Ansible Controller VMs /tmp
> folder, I don't see the files that are supposed to be created. The *names*
> are machine1, machine2 etc. I have tried changing localhost to 127.0.0.1
> but that didn't help me.
>
> The debug log reports success -
>
> changed: [machine1 -> localhost] => (item=machine1) => {"changed": true,
> ......"dest": "/tmp/machine1.ps1"....}
> changed: [machine2 -> localhost] => (item=machine1) => {"changed": true,
> ......"dest": "/tmp/machine2.ps1"....}
>
> Actually, the next step in my role is expected to copy the files generated
> in /tmp/ to a specified location in machine1, machine2 etc.
>
> What is wrong in my way of doing things?

Nothing, the code is correct.
Are you sure the files is not in /tmp on the control machine.

--
Kai Stian Olstad

Chethan S

unread,
Sep 28, 2016, 10:22:00 AM9/28/16
to Ansible Project, ansible-pr...@olstad.com
I am sure that the files aren't being created since there's hardly anything inside my /tmp and these files are not present either.

Chethan S

unread,
Sep 29, 2016, 2:27:58 AM9/29/16
to Ansible Project, ansible-pr...@olstad.com
I could figure out the solution. It turned out that the files, even though they were being created inside /tmp/ (I couldn't verify this, though) were being deleted instantly for whatever reason. Once I changed the destination to /var/tmp, I could see the files and even use them.
Reply all
Reply to author
Forward
0 new messages