63 lines
2.2 KiB
YAML
63 lines
2.2 KiB
YAML
- name: install icinga2 packages
|
|
ansible.builtin.apt:
|
|
name:
|
|
- icinga2
|
|
- icinga2-ido-mysql
|
|
- monitoring-plugins-basic
|
|
- monitoring-plugins-common
|
|
state: present
|
|
update_cache: true
|
|
|
|
- name: ensure icinga database exists
|
|
ansible.builtin.shell: |
|
|
mysql --socket={{ life_noc_db_root_socket }} -Nse "CREATE DATABASE IF NOT EXISTS {{ life_noc_db_icinga_name }} CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;"
|
|
changed_when: false
|
|
|
|
- name: ensure icinga database user exists and has grants
|
|
ansible.builtin.shell: |
|
|
mysql --socket={{ life_noc_db_root_socket }} -Nse "GRANT ALTER, CREATE, SELECT, INSERT, UPDATE, DELETE, DROP, CREATE VIEW, INDEX, EXECUTE ON {{ life_noc_db_icinga_name }}.* TO '{{ life_noc_db_icinga_user }}'@'localhost' IDENTIFIED BY '{{ life_noc_db_icinga_password }}'; FLUSH PRIVILEGES;"
|
|
changed_when: false
|
|
|
|
- name: check whether icinga ido schema is already imported
|
|
ansible.builtin.shell: |
|
|
mysql --socket={{ life_noc_db_root_socket }} -Nse "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='{{ life_noc_db_icinga_name }}' AND table_name='icinga_programstatus';"
|
|
register: life_noc_icinga_schema_check
|
|
changed_when: false
|
|
|
|
- name: import icinga ido schema
|
|
ansible.builtin.shell: |
|
|
mysql --socket={{ life_noc_db_root_socket }} {{ life_noc_db_icinga_name }} < /usr/share/icinga2-ido-mysql/schema/mysql.sql
|
|
when: life_noc_icinga_schema_check.stdout | trim == '0'
|
|
|
|
- name: install ido mysql feature configuration
|
|
ansible.builtin.template:
|
|
src: ido-mysql.conf.j2
|
|
dest: /etc/icinga2/features-available/ido-mysql.conf
|
|
owner: root
|
|
group: root
|
|
mode: "0644"
|
|
notify:
|
|
- validate icinga2
|
|
- restart icinga2
|
|
|
|
- name: enable ido-mysql feature
|
|
ansible.builtin.command: icinga2 feature enable ido-mysql
|
|
args:
|
|
creates: /etc/icinga2/features-enabled/ido-mysql.conf
|
|
notify:
|
|
- validate icinga2
|
|
- restart icinga2
|
|
|
|
- name: enable command feature
|
|
ansible.builtin.command: icinga2 feature enable command
|
|
args:
|
|
creates: /etc/icinga2/features-enabled/command.conf
|
|
notify:
|
|
- validate icinga2
|
|
- restart icinga2
|
|
|
|
- name: enable and start icinga2
|
|
ansible.builtin.service:
|
|
name: icinga2
|
|
enabled: true
|
|
state: started
|