0

I have an Ansible role run against X' number of servers and what I want to achieve is to have the Template upload to a different server.

I want to have all 'reports' from all tasks to a template file, but I want that template file to be hosted on a different server than the ones ansible run against. Is that possible, and how ?

So to give an example: Anbible run against server 1.1.1.1, collecting facts etc to a template file, Now I want that template file to be upload to a completely different server but includes the output of the 1.1.1.1 server. How this can be achieved ?

spiros_m
  • 41
  • 1
  • 4

1 Answers1

0

One option is to run the first task on 1.1.1.1 server, then once the template file is created, download this file using fetch module to the ansible server, then copy it to the different server. code below(not tested)

---
- hosts: 1.1.1.1
  tasks:
  - name: cat file
    command: cat /some/file
    register: output
  - name: write to file
    lineinfile:
     dest: "/tmp/test.file"
     line: "{{output.stdout}}"
     create: yes
     state: present
  - name: Download file
    fetch:
    src: "/tmp/test.file"
    dest: "/ansible/files/"
    flat: yes
- hosts: 2.2.2.2
  tasks:
  - name: copy file
    copy:
     src: /ansible/files/test.file
     dest: /tmp/location/

Smily
  • 2,308
  • 2
  • 17
  • 41
  • Yes, that's what I was thinking as well , the problem with this is that, on the second task is hanging cause is waiting for the ssh password (I guess). I cannot really use ssh keys on this setup. – spiros_m Oct 11 '19 at 14:13
  • can you configure password less ssh between ansible and this server? or else you need to prompt for password – Smily Oct 11 '19 at 14:36