2020-02-04 20:03:59 +00:00
|
|
|
# "How do i fail a task in Ansible if the variable contains a boolean value?
|
|
|
|
# I want to perform input validation for Ansible playbooks"
|
|
|
|
# https://stackoverflow.com/questions/46664127/how-do-i-fail-a-task-in-ansible-if-the-variable-contains-a-boolean-value-i-want/46667499#46667499
|
2020-01-24 01:57:14 +00:00
|
|
|
|
2020-02-04 20:03:59 +00:00
|
|
|
# We assume 0-init/tasks/validate_vars.yml has DEFINITELY been run, so no need
|
|
|
|
# to re-check whether vars are defined here. As Ansible vars cannot be unset:
|
|
|
|
# https://serverfault.com/questions/856729/how-to-destroy-delete-unset-a-variable-value-in-ansible
|
2017-05-27 18:09:50 +00:00
|
|
|
|
2020-02-04 20:03:59 +00:00
|
|
|
- name: Assert that "postgresql_install is sameas true" (boolean not string etc)
|
|
|
|
assert:
|
|
|
|
that: postgresql_install is sameas true
|
|
|
|
fail_msg: "PLEASE SET 'postgresql_install: True' e.g. IN: /etc/iiab/local_vars.yml"
|
|
|
|
quiet: yes
|
2017-05-27 18:09:50 +00:00
|
|
|
|
2020-02-04 20:03:59 +00:00
|
|
|
- name: Assert that "postgresql_enabled | type_debug == 'bool'" (boolean not string etc)
|
|
|
|
assert:
|
|
|
|
that: postgresql_enabled | type_debug == 'bool'
|
|
|
|
fail_msg: "PLEASE GIVE VARIABLE 'postgresql_enabled' A PROPER (UNQUOTED) ANSIBLE BOOLEAN VALUE e.g. IN: /etc/iiab/local_vars.yml"
|
|
|
|
quiet: yes
|
2017-05-27 18:09:50 +00:00
|
|
|
|
2020-02-04 20:03:59 +00:00
|
|
|
- debug:
|
|
|
|
var: postgresql_install
|
|
|
|
- debug:
|
|
|
|
var: postgresql_enabled
|
|
|
|
- debug:
|
|
|
|
var: postgresql_installed
|
2017-05-27 18:09:50 +00:00
|
|
|
|
|
|
|
|
2020-02-04 20:03:59 +00:00
|
|
|
- name: Install PostgreSQL if 'postgresql_installed' not defined, e.g. in {{ iiab_state_file }} # /etc/iiab/iiab_state.yml
|
|
|
|
include_tasks: install.yml
|
|
|
|
when: postgresql_installed is undefined
|
2017-05-27 18:09:50 +00:00
|
|
|
|
|
|
|
|
2020-02-04 20:03:59 +00:00
|
|
|
- name: Enable & Start 'postgresql-iiab' systemd service, if postgresql_enabled
|
2018-10-31 07:22:27 +00:00
|
|
|
systemd:
|
2017-12-08 08:53:07 +00:00
|
|
|
name: postgresql-iiab
|
2020-02-04 20:03:59 +00:00
|
|
|
daemon_reload: yes
|
2017-12-08 08:53:07 +00:00
|
|
|
enabled: yes
|
2020-02-04 20:03:59 +00:00
|
|
|
state: started
|
2020-10-16 20:46:19 +00:00
|
|
|
when: postgresql_enabled
|
2017-05-27 18:09:50 +00:00
|
|
|
|
2020-02-04 20:03:59 +00:00
|
|
|
- name: Disable & Stop 'postgresql-iiab' systemd service, if not postgresql_enabled
|
2018-10-31 07:22:27 +00:00
|
|
|
systemd:
|
2017-12-08 08:53:07 +00:00
|
|
|
name: postgresql-iiab
|
|
|
|
enabled: no
|
2020-02-04 20:03:59 +00:00
|
|
|
state: stopped
|
2017-10-27 03:58:56 +00:00
|
|
|
when: not postgresql_enabled
|
|
|
|
|
2020-01-24 16:21:15 +00:00
|
|
|
|
2018-10-31 07:22:27 +00:00
|
|
|
- name: Add 'postgresql' variable values to {{ iiab_ini_file }}
|
2017-12-08 08:53:07 +00:00
|
|
|
ini_file:
|
2020-02-04 20:03:59 +00:00
|
|
|
path: "{{ iiab_ini_file }}" # /etc/iiab/iiab_state.yml
|
2017-12-08 08:53:07 +00:00
|
|
|
section: postgresql
|
|
|
|
option: "{{ item.option }}"
|
2020-01-12 02:41:37 +00:00
|
|
|
value: "{{ item.value | string }}"
|
2017-05-27 18:09:50 +00:00
|
|
|
with_items:
|
|
|
|
- option: name
|
2017-12-08 10:38:26 +00:00
|
|
|
value: PostgreSQL
|
2017-05-27 18:09:50 +00:00
|
|
|
- option: description
|
|
|
|
value: '"PostgreSQL is a powerful, open source object-relational database system."'
|
2020-01-30 09:57:53 +00:00
|
|
|
- option: install
|
2017-05-27 18:09:50 +00:00
|
|
|
value: "{{ postgresql_install }}"
|
|
|
|
- option: enabled
|
|
|
|
value: "{{ postgresql_enabled }}"
|