commited current state (new functions, may not work by now)
This commit is contained in:
43
playbooks/managed-mailcow/count-mailboxes.yml
Normal file
43
playbooks/managed-mailcow/count-mailboxes.yml
Normal file
@@ -0,0 +1,43 @@
|
||||
---
|
||||
- name: Mailcow Mailbox Counter
|
||||
hosts: all
|
||||
gather_facts: no
|
||||
tasks:
|
||||
- import_role:
|
||||
name: managed-mailcow
|
||||
tasks_from: find-mailcow-composedir.yml
|
||||
|
||||
- name: Read mailcow.conf and extract DBROOT
|
||||
ansible.builtin.shell: |
|
||||
bash -c 'source {{ mailcow_dir_result.files[0].path }}/mailcow.conf && echo $DBROOT'
|
||||
register: dbroot_output
|
||||
|
||||
- name: Count active mailboxes from mailcow database
|
||||
ansible.builtin.shell: |
|
||||
docker compose exec mysql-mailcow \
|
||||
mysql -u root -p{{ dbroot_output.stdout }} -D mailcow -N -e \
|
||||
"SELECT COUNT(*) FROM mailbox WHERE active=1;"
|
||||
args:
|
||||
chdir: "{{ mailcow_dir_result.files[0].path }}"
|
||||
register: mailbox_count
|
||||
changed_when: false
|
||||
|
||||
- name: Set fact with mailbox count as integer
|
||||
ansible.builtin.set_fact:
|
||||
mailbox_count_int: "{{ mailbox_count.stdout | int }}"
|
||||
|
||||
- name: Summiere alle Mailboxen über alle Hosts
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
run_once: true
|
||||
tasks:
|
||||
|
||||
- name: Summiere aktive Mailboxen
|
||||
ansible.builtin.set_fact:
|
||||
total_mailboxes: "{{ (total_mailboxes | default(0) | int) + (item.value.mailbox_count_int | default(0) | int) }}"
|
||||
loop: "{{ hostvars | dict2items }}"
|
||||
when: "'mailbox_count_int' in item.value"
|
||||
|
||||
- name: Zeige Gesamtsumme
|
||||
ansible.builtin.debug:
|
||||
msg: "Gesamtanzahl aktiver Mailboxen: {{ total_mailboxes }}"
|
||||
Reference in New Issue
Block a user