Ansible: Accumulate output across multiple hosts on task run

前端 未结 1 1879
死守一世寂寞
死守一世寂寞 2021-01-05 06:09

I have the following playbook

- hosts: all
  gather_facts: False
  tasks:
    - name: Check status of applications
      shell: somecommand
      register: r         


        
相关标签:
1条回答
  • 2021-01-05 06:55

    You can extract result from hostvars inside a run_once task:

    - hosts: mygroup
      gather_facts: false
      tasks:
        - shell: date
          register: date_res
          changed_when: false
        - debug:
            msg: "{{ ansible_play_hosts | map('extract', hostvars, 'date_res') | map(attribute='stdout') | list }}"
          run_once: yes
    

    This will print out a list of all date_res.stdout from all hosts in the current play and run this task only once.

    0 讨论(0)
提交回复
热议问题