0

I'm trying to figure out how one would copy or write the contents of a slurped variable to a remote (preferable) file. If this is not possible, what's the cleanest way to do it in steps?

I have something like this:

- name: Load r user public key   
  slurp: 
    src: *path*   
  register: slurped_r_key

- name: Decode r key   
  set_fact:
    r_content: "{{ slurped_r_key.content | b64decode }}"

I want to get the contents of {{ r_content }} into a file in the remote machines that are part of an inventory group. If I cannot do that directly, what's the best way? Should I copy the contents to a local file and then scp the file over to the remote machines?

Thanks in advance!

  • In this case, [`fetch`](https://docs.ansible.com/ansible/latest/modules/fetch_module.html) and later [`copy`](https://docs.ansible.com/ansible/latest/modules/copy_module.html) seem to be much more indicated. – Zeitounator Jan 20 '20 at 14:26

1 Answers1

0

To copy the variable to a file you can try as below:

  - name: copy
    copy:
     content: "{{r_content}}"
     dest: /tmp/testing


Smily
  • 2,308
  • 2
  • 17
  • 41
  • As https://docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html#ansible-collections-ansible-builtin-copy-module says: "Using a variable in the content field will result in unpredictable output" – Paweł May 17 '23 at 10:34