Answers: <p>Use Ansible callback.</p>
  
  <p>Stop looking at log files. Use log aggregation technology like Logstash.</p>
  
  <p><a href="https://github.com/ujenmr/ansible-logstash-callback" rel="nofollow noreferrer">https://github.com/ujenmr/ansible-logstash-callback</a></p>
  
  <p>see also:
  <a href="https://groups.google.com/forum/#!topic/ansible-project/zOjsYxLN578" rel="nofollow noreferrer">https://groups.google.com/forum/#!topic/ansible-project/zOjsYxLN578</a></p>
  
Answers: CC BY-SA 3.0
Answers: 2017-10-25T18:34:50.747Z
Answers: 2017-10-25T18:34:50.747Z
Answers: Jeremy
Answers: <p>This question has two approaches, and both has answers on SO:</p>
  
  <ol>
  <li><p>Convert all Ansible output to JSON with <code>json</code> stdout callback and parse it with your favourite tools. The <code>eos_command</code> output for each device will be under different host key in the resulting json.
  See <a href="https://stackoverflow.com/a/39037249/2795592">this</a> and <a href="https://stackoverflow.com/a/44717744/2795592">this</a>.</p></li>
  <li><p>Make <code>run_once</code> task to collect data from other hosts, like this:</p>
  
  <pre><code>- debug:
      msg: "{{ ansible_play_hosts | map('extract', hostvars, 'result') | map(attribute='stdout_lines') | list }}"
    run_once: yes
  </code></pre>
  
  <p>See <a href="https://stackoverflow.com/a/43908569/2795592">this</a>.</p></li>
  </ol>
  
Answers: CC BY-SA 3.0
Answers: 2017-10-24T14:02:36.953Z
Answers: 2017-10-24T14:02:36.953Z
Answers: Konstantin Suvorov
Body: <p>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.</p>
  
  <p>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.</p>
  
  <pre><code>---
  - name: Checks
    hosts: myhosts
    connection: local
  
    tasks:
    - name: Run Commands
      eos_command:
       commands:
        - show ip pim neighbor | json
        - show ip bgp summary | json
      register: result
  
    - name: Save to file
      copy: 
       content: "{{ result.stdout_lines | to_nice_json }}"
      dest: "/home/homedirectory/results.json"
  </code></pre>
  
  <p>Would there be way to log both (and eventually all production) devices in the same file?</p>
  
Tags: <ansible>
Title: How to log outcome from multiple hosts in Ansible?
UserDisplayName: CEamonn
ThreadText: # How to log outcome from multiple hosts in Ansible?
  
  (Asked by: username_0 on 2017-10-24)
  
  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
  
    tasks:
    - name: Run Commands
      eos_command:
       commands:
        - show ip pim neighbor | json
        - show ip bgp summary | json
      register: result
  
    - name: Save to file
      copy: 
       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?
  
  **Tags:** ansible
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2017-10-24. Score: 8 | Accepted answer
  
  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](https://stackoverflow.com/a/39037249/2795592) and [this](https://stackoverflow.com/a/44717744/2795592).
  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](https://stackoverflow.com/a/43908569/2795592).
  
  
  ---
  
  ### Answer by username_1 on 2017-10-25. Score: 1
  
  Use Ansible callback.
  
  Stop looking at log files. Use log aggregation technology like Logstash.
  
  <https://github.com/ujenmr/ansible-logstash-callback>
  
  see also:
  <https://groups.google.com/forum/#!topic/ansible-project/zOjsYxLN578>
  
  
  ---
  
  