I'm trying to write a script to publish basic configurations for any new devices. Also to assert compliancy of basic configuration for devices in production.

Trying to gather all the lines executed, on each devices, coming from the different plays, that I call on a central one.

How to centralize the outputs, (the commands that ansible will execute) and possibly assemble it into one file?

Trying to gather the commands in check mode in order to confirm before execution.

1 Answer 1


As mentioned in Ansible: lineinfile for several lines?

- name: "create block in own file per host"
     path: "/dir/logs/{{ inventory_hostname }}.txt"
     create: true
     block: "some commands"

- name: "add more line in block (even if already executed on another host)"
     line: "{{ item }}"
  loop: "{{ more_commands_1 | default([]) +
    more_commands_2 | default([]) }}" 

- name: "assemble all files in one"
    src: "/dir/logs/"
    dest: "/dir/logs/all_hosts.txt"

I used those modules along with check_mode: false and delegate_to: localhost.

Those are handlers (in a role). I notify them in each module that execute commands on a device.

Would be glad to use a more clever solution if it exists.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.