Add ansible/playbooks/docker-count.yml
This commit is contained in:
parent
e1fb5120c8
commit
03f8a96b74
1 changed files with 21 additions and 0 deletions
21
ansible/playbooks/docker-count.yml
Normal file
21
ansible/playbooks/docker-count.yml
Normal file
|
@ -0,0 +1,21 @@
|
|||
---
|
||||
- name: Count Docker containers on all hosts
|
||||
hosts: all
|
||||
gather_facts: no
|
||||
tasks:
|
||||
- name: Count running Docker containers on each host
|
||||
shell: "docker ps -q | wc -l"
|
||||
register: container_count
|
||||
changed_when: false
|
||||
|
||||
- name: Display count for each host
|
||||
debug:
|
||||
msg: "Host {{ inventory_hostname }} has {{ container_count.stdout }} running Docker containers"
|
||||
|
||||
- name: Aggregate total count
|
||||
run_once: true
|
||||
delegate_to: localhost
|
||||
vars:
|
||||
container_counts: "{{ hostvars | map(attribute='container_count.stdout') | map('int') | list }}"
|
||||
debug:
|
||||
msg: "Total running Docker containers across all hosts: {{ container_counts | sum }}"
|
Loading…
Reference in a new issue