# Best way to accomplish this task using slurp

**URL:** <https://forum.ansible.com/t/best-way-to-accomplish-this-task-using-slurp/19538>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [October 18, 2015, 6:07pm UTC](https://forum.ansible.com/t/best-way-to-accomplish-this-task-using-slurp/19538 "2015-10-18T18:07:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CyberCyber](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@CyberCyber](https://forum.ansible.com/u/CyberCyber)\
**Post date:** [October 18, 2015, 6:07pm UTC](https://forum.ansible.com/t/best-way-to-accomplish-this-task-using-slurp/19538/1 "2015-10-18T18:07:05Z")

</div>

I’m using Ansible version 1.9.4 on Ubuntu 14. This is the approach that I’ve tried, but it does not work:

hosts file:  
[server\_A]  
172.19.99.15

[server\_B]  
172.19.99.16

playbook:

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [October 19, 2015, 7:40pm UTC](https://forum.ansible.com/t/best-way-to-accomplish-this-task-using-slurp/19538/2 "2015-10-19T19:40:52Z")

</div>

several things wrong there, but im just going to give you some thing  
that should 'just work'

- name: part one of playbook  
&nbsp;&nbsp;hosts: server\_A  
&nbsp;&nbsp;gather\_facts: no

&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;- name: slurp a file  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;slurp: src=/tmp/test.txt  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: fileContents

&nbsp;&nbsp;&nbsp;- debug: msg="{{ fileContents.content | b64decode }}"

&nbsp;&nbsp;&nbsp;- template: src=file\_contents.j2 dest=/tmp/test.txt  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delegate\_to: server\_B

where file\_contents.j2:  
{{ fileContents.content | b64decode }}

---

<div class="post-metadata">

**Author:** ![CyberCyber](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@CyberCyber](https://forum.ansible.com/u/CyberCyber)\
**Post date:** [October 21, 2015, 1:39am UTC](https://forum.ansible.com/t/best-way-to-accomplish-this-task-using-slurp/19538/3 "2015-10-21T01:39:33Z")

</div>

Hi Brian,

Can you elaborate on the several things that are wrong with the approach taken above? It seems dynamic variables do not carry over from each play. Is this intentional ?

Your suggestion would work, but won’t that require server\_B to have access to server\_A. What if that is not an option? It’s possible to use fetch and store the file locally on the control server, but what if I am trying to avoid doing that? Is there another approach using slurp ?

Thanks.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [October 21, 2015, 11:41pm UTC](https://forum.ansible.com/t/best-way-to-accomplish-this-task-using-slurp/19538/4 "2015-10-21T23:41:16Z")

</div>

> Can you elaborate on the several things that are wrong with the approach  
> taken above? It seems dynamic variables do not carry over from each play. Is  
> this intentional ?

play vars are not carry over, but host associated vars do, you just  
need to access them through the host they are associated with.

> Your suggestion would work, but won't that require server\_B to have access  
> to server\_A. What if that is not an option? It's possible to use fetch and  
> store the file locally on the control server, but what if I am trying to  
> avoid doing that? Is there another approach using slurp ?

slurp copies the file to the 'controller' (machine you run ansible  
from), so the servers do not need any access to each other.
