Best way to accomplish this task using slurp

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:

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

- name: part one of playbook
  hosts: server_A
  gather_facts: no

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

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

   - template: src=file_contents.j2 dest=/tmp/test.txt
     delegate_to: server_B

where file_contents.j2:
{{ fileContents.content | b64decode }}

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.

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.