We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e1fb512 commit 03f8a96Copy full SHA for 03f8a96
ansible/playbooks/docker-count.yml
@@ -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
21
+ msg: "Total running Docker containers across all hosts: {{ container_counts | sum }}"
0 commit comments