Neuigkeiten | Termine | Blog


File Transfer between Ansible Nodes

Have you ever wanted to transfer files between different Ansible nodes and i do not mean between the control machine and the managed nodes? Then this post might be helpful for you. 

Instead of using the synchronize module or copying the file to the control machine first and distribute them from here, there is much simpler solution to achieve this at least for small files.

In this example we want to transfer a certificate signing request from the managed node to our certificate authority

First read the file on the node and assign the content to a variable

					- name: Read file and assign to variable csr
   command: cat /the/path/to/your/csrfile.csr
   changed_when: false
   register: csr

The variable can now be used to write out the file to the ca using the standard copy module:

					- name: Write out csr on ca
 copy: content={{csr.stdout}} dest=/some/path/on/your/ca/csrfile.csr
 delegate_to: certificate_authority

Simple, effective and without the need to write temporary files or allow ssh-access between nodes.