ansible-base/roles/icinga2_server/tasks/configure_icingaweb2.yml
2020-10-03 12:00:19 +02:00

109 lines
4.2 KiB
YAML

---
- name: Icingaweb2 config file deployed
template:
src: '{{ item }}.j2'
dest: '/etc/icingaweb2/{{ item }}'
owner: root
group: icingaweb2
mode: 0660
loop:
- config.ini
- resources.ini
- roles.ini
- groups.ini
- authentication.ini
no_log: True
- name: icingaweb2 modules directory created
file:
name: /etc/icingaweb2/modules/monitoring
state: directory
owner: root
group: icingaweb2
mode: 0750
- name: icingaweb2 enabledModules directory created
file:
name: /etc/icingaweb2/enabledModules
state: directory
owner: root
group: icingaweb2
mode: 0750
- name: icingaweb2 monitoring module enabled
file:
src: /usr/share/icingaweb2/modules/monitoring
dest: /etc/icingaweb2/enabledModules/monitoring
state: link
mode: 0750
- name: icingaweb2 monitoring module configured
template:
src: modules_config.ini.j2
dest: /etc/icingaweb2/modules/monitoring/config.ini
owner: root
group: icingaweb2
mode: 0660
- name: icingaweb2 monitoring module commandtransport configured
template:
src: modules_commandtransports.ini.j2
dest: /etc/icingaweb2/modules/monitoring/commandtransports.ini
owner: root
group: icingaweb2
mode: 0660
- name: icingaweb2 monitoring module backends configured
template:
src: modules_backends.ini.j2
dest: /etc/icingaweb2/modules/monitoring/backends.ini
owner: root
group: icingaweb2
mode: 0660
- name: check if Icingaweb2 table and user in MariaDB exist
shell: mysql -u root icingaweb2 -e "SHOW TABLES;" |grep icingaweb_user
register: icinga2_server_register_icingaweb2_imported
changed_when: icinga2_server_register_icingaweb2_imported.rc == 1
failed_when: "'Access denied for' in icinga2_server_register_icingaweb2_imported.stderr"
- name: Icingaweb2 DB schema imported
mysql_db:
state: import
name: icingaweb2
target: "{{ icinga2_server_mariadb_icingaweb2_schema_location }}"
when: icinga2_server_register_icingaweb2_imported.rc == 1
- name: check if Icingaweb2 main user exist
shell: mysql -u root icingaweb2 -e "SELECT * FROM icingaweb2.icingaweb_user;" |grep "{{ icinga2_server_icingaweb2_main_user }}"
register: icinga2_server_register_icingaweb2_main_user_exist
changed_when: icinga2_server_register_icingaweb2_main_user_exist.rc == 1
failed_when: "'Access denied for' in icinga2_server_register_icingaweb2_main_user_exist.stderr"
no_log: True
- name: insert icingaweb2 main user into database
command: mysql -u root icingaweb2 -e "INSERT INTO icingaweb_user (name, active, password_hash) VALUES ('{{ icinga2_server_icingaweb2_main_user }}', 1, '{{ icinga2_server_icingaweb2_main_user_password_hash_manual }}')"
when: icinga2_server_register_icingaweb2_main_user_exist.rc == 1
no_log: True
- name: check if Icingaweb2 Administrators group exist
shell: mysql -u root icingaweb2 -e "SELECT * FROM icingaweb2.icingaweb_group;" |grep Administrators
register: icinga2_server_register_icingaweb2_administrators_group_exist
changed_when: icinga2_server_register_icingaweb2_administrators_group_exist.rc == 1
failed_when: "'Access denied for' in icinga2_server_register_icingaweb2_administrators_group_exist.stderr"
- name: insert Icingaweb2 Administrators group into database
command: mysql -u root icingaweb2 -e "INSERT INTO icingaweb_group (name) VALUES ('Administrators')"
when: icinga2_server_register_icingaweb2_administrators_group_exist.rc == 1
- name: check if main user in Icingaweb2 Administrators group
shell: mysql -u root icingaweb2 -e "SELECT * FROM icingaweb2.icingaweb_group_membership;" |grep "{{ icinga2_server_icingaweb2_main_user }}"
register: icinga2_server_register_icingaweb2_main_user_in_administrators_group
changed_when: icinga2_server_register_icingaweb2_main_user_in_administrators_group.rc == 1
failed_when: "'Access denied for' in icinga2_server_register_icingaweb2_main_user_in_administrators_group.stderr"
- name: main user in Icingaweb2 Administrators group
command: mysql -u root icingaweb2 -e "INSERT INTO icingaweb_group_membership (group_id, username) VALUES ('1', '{{ icinga2_server_icingaweb2_main_user }}')"
when: icinga2_server_register_icingaweb2_main_user_in_administrators_group.rc == 1