update docker count
This commit is contained in:
parent
5410fd2bf1
commit
ccc8547e4d
1 changed files with 12 additions and 6 deletions
|
@ -1,7 +1,7 @@
|
||||||
---
|
---
|
||||||
- name: Count Docker containers on all hosts
|
- name: Count Docker containers on all hosts
|
||||||
hosts: all
|
hosts: all
|
||||||
gather_facts: no
|
gather_facts: false
|
||||||
tasks:
|
tasks:
|
||||||
- name: Count running Docker containers on each host
|
- name: Count running Docker containers on each host
|
||||||
shell: "docker ps -q | wc -l"
|
shell: "docker ps -q | wc -l"
|
||||||
|
@ -13,9 +13,15 @@
|
||||||
msg: "Host {{ inventory_hostname }} has {{ container_count.stdout }} running Docker containers"
|
msg: "Host {{ inventory_hostname }} has {{ container_count.stdout }} running Docker containers"
|
||||||
|
|
||||||
- name: Aggregate total count
|
- name: Aggregate total count
|
||||||
run_once: true
|
hosts: localhost
|
||||||
delegate_to: localhost
|
gather_facts: false
|
||||||
vars:
|
tasks:
|
||||||
container_counts: "{{ hostvars | map(attribute='container_count.stdout') | map('int') | list }}"
|
- name: Collect container counts from all hosts
|
||||||
|
set_fact:
|
||||||
|
container_counts: >-
|
||||||
|
{{ hostvars | dict2items | selectattr('value.container_count', 'defined') |
|
||||||
|
map(attribute='value.container_count.stdout') | map('int') | list }}
|
||||||
|
|
||||||
|
- name: Display total running Docker containers
|
||||||
debug:
|
debug:
|
||||||
msg: "Total running Docker containers across all hosts: {{ container_counts | sum }}"
|
msg: "Total running Docker containers across all hosts: {{ container_counts | sum }}"
|
||||||
|
|
Loading…
Reference in a new issue