I've a playbook that runs EOS commands against multiple devices. Currently the whole thing is done in bash, creates one massive text file log and an engineer compares each day's log to the previous one for irregularities.

I'm attempting to have one simple playbooks that runs the commands and logs to json from which it'll be easier to automate the comparison, but I've just realised only logs from one device are saved as opposed to the two I'm testing against.

- name: Checks
  hosts: myhosts
  connection: local

  - name: Run Commands
      - show ip pim neighbor | json
      - show ip bgp summary | json
    register: result

  - name: Save to file
     content: "{{ result.stdout_lines | to_nice_json }}"
    dest: "/home/homedirectory/results.json"

Would there be way to log both (and eventually all production) devices in the same file?

2 Answers 2


This question has two approaches, and both has answers on SO:

  1. Convert all Ansible output to JSON with json stdout callback and parse it with your favourite tools. The eos_command output for each device will be under different host key in the resulting json. See this and this.

  2. Make run_once task to collect data from other hosts, like this:

    - debug:
        msg: "{{ ansible_play_hosts | map('extract', hostvars, 'result') | map(attribute='stdout_lines') | list }}"
      run_once: yes

    See this.


Use Ansible callback.

Stop looking at log files. Use log aggregation technology like Logstash.


see also: https://groups.google.com/forum/#!topic/ansible-project/zOjsYxLN578

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.