Skip to content

Commit

Permalink
Fix postgresql without zabbix
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandermeindl committed Jul 8, 2023
1 parent 483a82e commit 5efc51e
Showing 1 changed file with 51 additions and 56 deletions.
107 changes: 51 additions & 56 deletions roles/postgresql/tasks/zabbix.yml
Original file line number Diff line number Diff line change
@@ -1,65 +1,60 @@
---
- name: Stats for zabbix config
ansible.builtin.stat:
path: /etc/zabbix
register: zabbix_config_exists

- name: Add zabbix PostgreSQL user
become_user: postgres
become: true
community.postgresql.postgresql_user:
name: '{{ postgresql_zabbix_user }}'
password: '{{ postgresql_zabbix_password }}'
state: present
no_log: true
- name: With zabbix monitoring
when: zabbix_monitoring
block:
- name: Add zabbix PostgreSQL user
become_user: postgres
become: true
community.postgresql.postgresql_user:
name: '{{ postgresql_zabbix_user }}'
password: '{{ postgresql_zabbix_password }}'
state: present
no_log: true

- name: Set zabbix PostgreSQL grant
community.postgresql.postgresql_membership:
group: pg_monitor
target_roles: "{{ postgresql_zabbix_user }}"
state: present
become_user: postgres
become: true
- name: Set zabbix PostgreSQL grant
community.postgresql.postgresql_membership:
group: pg_monitor
target_roles: "{{ postgresql_zabbix_user }}"
state: present
become_user: postgres
become: true

- name: Install sudoer access for zabbix
ansible.builtin.copy:
src: sudoers.d/postgresql
dest: /etc/sudoers.d/postgresql
mode: 0440
when: zabbix_monitoring
- name: Install sudoer access for zabbix
ansible.builtin.copy:
src: sudoers.d/postgresql
dest: /etc/sudoers.d/postgresql
mode: 0440

- name: Install zabbix sql PostgreSQL files
ansible.posix.synchronize:
src: zabbix/postgresql
dest: '{{ zabbix_agent_home }}'
# NOTE: workaroud for string problem
# @SEE https://github.com/ansible-collections/ansible.posix/issues/376#issuecomment-1222046195
dest_port: "{{ lookup('ansible.builtin.vars', 'ansible_port', default=22) }}"
group: false
owner: false
when: zabbix_monitoring
- name: Install zabbix sql PostgreSQL files
ansible.posix.synchronize:
src: zabbix/postgresql
dest: '{{ zabbix_agent_home }}'
# NOTE: workaroud for string problem
# @SEE https://github.com/ansible-collections/ansible.posix/issues/376#issuecomment-1222046195
dest_port: "{{ lookup('ansible.builtin.vars', 'ansible_port', default=22) }}"
group: false
owner: false

# @TODO: this does not work with synchronize at the moment
- name: Set owner for sql PostgreSQL files
ansible.builtin.file:
path: '{{ zabbix_agent_home }}/postgresql'
state: directory
recurse: true
owner: zabbix
group: zabbix
when: zabbix_monitoring
# @TODO: this does not work with synchronize at the moment
- name: Set owner for sql PostgreSQL files
ansible.builtin.file:
path: '{{ zabbix_agent_home }}/postgresql'
state: directory
recurse: true
owner: zabbix
group: zabbix

- name: Remove zabbix PostgreSQL user
become_user: postgres
become: true
community.postgresql.postgresql_user:
name: '{{ postgresql_zabbix_user }}'
state: absent
- name: Without zabbix monitoring
when: not zabbix_monitoring
block:
- name: Remove zabbix PostgreSQL user
become_user: postgres
become: true
community.postgresql.postgresql_user:
name: '{{ postgresql_zabbix_user }}'
state: absent

- name: Remove zabbix sql postgresql files
ansible.builtin.file:
path: '{{ zabbix_agent_home }}/postgresql'
state: absent
when: not zabbix_monitoring
- name: Remove zabbix sql postgresql files
ansible.builtin.file:
path: '{{ zabbix_agent_home }}/postgresql'
state: absent

0 comments on commit 5efc51e

Please sign in to comment.