Skip to content

Commit

Permalink
Fix icingaweb2 postgres (#172)
Browse files Browse the repository at this point in the history
* removed ternary statement 

* add quotes to make psql command working

* fix admin user exists task (removed -c)

* fix when statement because there is always an output
  • Loading branch information
Alpha041087 authored Aug 1, 2023
1 parent 05be1a9 commit 4fe7e11
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions roles/icinga2/tasks/features/idopgsql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
psqlcmd: >-
PGPASSWORD="{{ icinga2_dict_features.idopgsql.password }}"
psql
host={{ icinga2_dict_features.idopgsql.host| default('localhost') }}
"host={{ icinga2_dict_features.idopgsql.host| default('localhost') }}
port={{ icinga2_dict_features.idopgsql.port| default('5432') }}
user={{ icinga2_dict_features.idopgsql.user| default('icinga2') }}
dbname={{ icinga2_dict_features.idopgsql.database |default('icinga2') }}
{% if icinga2_dict_features.idopgsql.ssl_mode is defined %} sslmode={{ icinga2_dict_features.idopgsql.ssl_mode | default('require') }} {%- endif %}
{% if icinga2_dict_features.idopgsql.ssl_cert is defined %} sslcert={{ icinga2_dict_features.idopgsql.ssl_cert }} {%- endif %}
{% if icinga2_dict_features.idopgsql.ssl_key is defined %} sslkey={{ icinga2_dict_features.idopgsql.ssl_key }} {%- endif %}
{% if icinga2_dict_features.idopgsql.extra_options is defined %} {{ icinga2_dict_features.idopgsql.extra_options }} {%- endif %}
{% if icinga2_dict_features.idopgsql.extra_options is defined %} {{ icinga2_dict_features.idopgsql.extra_options }} {%- endif %}"
- name: PostgreSQL check for IDO schema
shell: >
Expand Down
2 changes: 1 addition & 1 deletion roles/icingaweb2/tasks/manage_icingaweb_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
_i2_config_hash:
icingaweb2_db:
type: db
db: "{{ icingaweb2_db['type'] | ternary('mysql', 'pgsql') }}"
db: "{{ icingaweb2_db['type'] | default('mysql') }}"
host: "{{ icingaweb2_db['host'] }}"
dbname: "{{ icingaweb2_db['name'] }}"
username: "{{ icingaweb2_db['user'] }}"
Expand Down
8 changes: 4 additions & 4 deletions roles/icingaweb2/tasks/manage_icingaweb_pgsql_db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
_tmp_pgsqlcmd: >-
PGPASSWORD="{{ icingaweb2_priv_db_password | default(icingaweb2_db['password']) }}"
psql
host={{ icingaweb2_db['host'] }}
"host={{ icingaweb2_db['host'] }}
{% if icingaweb2_db['port'] is defined %} port={{ icingaweb2_db['port'] }} {%- endif %}
user={{ icingaweb2_priv_db_user | default(icingaweb2_db['user']) }}
dbname={{ icingaweb2_db['name'] }}
{% if icingaweb2_db['ssl_mode'] is defined %} sslmode={{ icingaweb2_db['ssl_mode'] | default('require') }} {%- endif %}
{% if icingaweb2_db['ssl_cert'] is defined %} sslcert={{ icingaweb2_db['ssl_cert'] }} {%- endif %}
{% if icingaweb2_db['ssl_key'] is defined %} sslkey={{ icingaweb2_db['ssl_key'] }} {%- endif %}
{% if icingaweb2_db['ssl_extra_options'] is defined %} {{ icingaweb2_db['ssl_extra_options'] }} {%- endif %}
{% if icingaweb2_db['ssl_extra_options'] is defined %} {{ icingaweb2_db['ssl_extra_options'] }} {%- endif %}"
- name: PostgreSQL check for IDO schema
ansible.builtin.shell: >
Expand Down Expand Up @@ -54,8 +54,8 @@
- name: Ensure admin user exists
ansible.builtin.shell: >-
echo "INSERT INTO icingaweb_user (name, active, password_hash) VALUES ('{{ icingaweb2_admin_username }}', 1,
'"`php -r 'echo password_hash("{{ icingaweb2_admin_password }}", PASSWORD_DEFAULT);'`"')" | {{ _tmp_pgsqlcmd }} -w -c
when: _icingaweb2_db_user.stdout_lines | length <= 0
'"`php -r 'echo password_hash("{{ icingaweb2_admin_password }}", PASSWORD_DEFAULT);'`"')" | {{ _tmp_pgsqlcmd }} -w
when: '"(0 rows)" in _icingaweb2_db_user.stdout_lines'
when:
- icingaweb2_admin_username is defined
- icingaweb2_admin_password is defined

0 comments on commit 4fe7e11

Please sign in to comment.