Skip to content

Commit 03f8a96

Browse files
author
mafyuh
committedDec 20, 2024
Add ansible/playbooks/docker-count.yml
1 parent e1fb512 commit 03f8a96

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
 

‎ansible/playbooks/docker-count.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
- name: Count Docker containers on all hosts
3+
hosts: all
4+
gather_facts: no
5+
tasks:
6+
- name: Count running Docker containers on each host
7+
shell: "docker ps -q | wc -l"
8+
register: container_count
9+
changed_when: false
10+
11+
- name: Display count for each host
12+
debug:
13+
msg: "Host {{ inventory_hostname }} has {{ container_count.stdout }} running Docker containers"
14+
15+
- name: Aggregate total count
16+
run_once: true
17+
delegate_to: localhost
18+
vars:
19+
container_counts: "{{ hostvars | map(attribute='container_count.stdout') | map('int') | list }}"
20+
debug:
21+
msg: "Total running Docker containers across all hosts: {{ container_counts | sum }}"

0 commit comments

Comments
 (0)
Please sign in to comment.