|
1 | 1 | --- |
2 | | - |
3 | | -- name: MySQL check for icingaweb db schema |
| 2 | +- name: MySQL create Icinga Web 2 user |
4 | 3 | ansible.builtin.shell: > |
5 | 4 | {{ _tmp_mysqlcmd }} |
6 | 5 | -Ns -e "select name from icingaweb_user where name like '{{ _current_user.username }}'" |
7 | | - failed_when: false |
8 | | - changed_when: false |
9 | | - check_mode: false |
| 6 | + | grep '{{ _current_user.username }}' || |
| 7 | + ( |
| 8 | + echo "INSERT INTO icingaweb_user (name, active, password_hash) VALUES ('{{ _current_user.username }}', 1, |
| 9 | + '"`php -r 'echo password_hash("{{ _current_user.password }}", PASSWORD_DEFAULT);'`"') |
| 10 | + ON DUPLICATE KEY UPDATE active = 1, password_hash = '"`php -r 'echo password_hash("{{ _current_user.password }}", PASSWORD_DEFAULT);'`"'" | {{ _tmp_mysqlcmd }} -Ns && |
| 11 | + echo "User created" |
| 12 | + ) |
10 | 13 | register: _icingaweb2_db_user |
| 14 | + when: (_current_user.recreate | default(false)) is false |
| 15 | + changed_when: |
| 16 | + - '"User created" in _icingaweb2_db_user.stdout_lines' |
| 17 | + throttle: 1 |
11 | 18 |
|
12 | | -- name: Create user in Icinga Web (or reenable user / reset password) |
13 | | - run_once: true |
14 | | - ansible.builtin.shell: >- |
| 19 | +- name: MySQL recreate Icinga Web 2 user |
| 20 | + ansible.builtin.shell: > |
15 | 21 | echo "INSERT INTO icingaweb_user (name, active, password_hash) VALUES ('{{ _current_user.username }}', 1, |
16 | 22 | '"`php -r 'echo password_hash("{{ _current_user.password }}", PASSWORD_DEFAULT);'`"') |
17 | 23 | ON DUPLICATE KEY UPDATE active = 1, password_hash = '"`php -r 'echo password_hash("{{ _current_user.password }}", PASSWORD_DEFAULT);'`"'" | {{ _tmp_mysqlcmd }} -Ns |
18 | | - when: (_icingaweb2_db_user.stdout_lines | length <= 0) or (_current_user.recreate is true) |
| 24 | + when: (_current_user.recreate | default(false)) is true |
| 25 | + throttle: 1 |
0 commit comments