From 03f8a96b74591ef91a1d1cbf0303e7cb6b751354 Mon Sep 17 00:00:00 2001 From: mafyuh Date: Fri, 20 Dec 2024 01:45:42 -0500 Subject: [PATCH] Add ansible/playbooks/docker-count.yml --- ansible/playbooks/docker-count.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 ansible/playbooks/docker-count.yml diff --git a/ansible/playbooks/docker-count.yml b/ansible/playbooks/docker-count.yml new file mode 100644 index 0000000..2434203 --- /dev/null +++ b/ansible/playbooks/docker-count.yml @@ -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 }}"