diff --git a/README.md b/README.md index 14c4966..a7b467d 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ This role installs and configures PostgreSQL instances. |---|---|---|---| | `version` | no | `16` | PostgreSQL version to be installed. Defaults to `17`. | | `enabled` | no | `true` | Auto-start PostgreSQL upon boot or not. Defaults to `false`. | +| `port` | no | `5555` | Set port to listen on. Defaults to `5432`. | ## Examples @@ -19,6 +20,7 @@ This role installs and configures PostgreSQL instances. vars: version: 16 enabled: true + port: 6789 ``` ## Return Values diff --git a/tasks/config.yml b/tasks/config.yml new file mode 100644 index 0000000..a45962c --- /dev/null +++ b/tasks/config.yml @@ -0,0 +1,21 @@ +--- +- name: Configure PostgreSQL include location + ini_file: + path: "/var/lib/pgsql/{{ eff_pg_version }}/data/postgresql.conf" + option: include_dir + value: "'/etc/postgresql/{{ eff_pg_version }}/main/conf.d'" + create: false + mode: '0644' + owner: "{{ noobient_pg_user }}" + group: "{{ noobient_pg_group }}" + when: ansible_os_family == 'RedHat' + +- name: Configure PostgreSQL port + ini_file: + path: "/etc/postgresql/{{ eff_pg_version }}/main/conf.d/port.conf" + option: port + value: "{{ eff_pg_port }}" + create: true + mode: '0644' + owner: "{{ noobient_pg_user }}" + group: "{{ noobient_pg_group }}" diff --git a/tasks/main.yml b/tasks/main.yml index 70264d8..0ab371c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -11,3 +11,4 @@ when: ansible_os_family == 'RedHat' - include_tasks: systemd.yml +- include_tasks: config.yml diff --git a/tests/main.yml b/tests/main.yml index d2b515b..2544f19 100644 --- a/tests/main.yml +++ b/tests/main.yml @@ -8,3 +8,5 @@ name: "{{ playbook_dir.split('/')[:-1] | last }}" vars: version: 16 + enabled: true + port: 7777 diff --git a/vars/main.yml b/vars/main.yml index 52d103d..70f6711 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,6 +1,12 @@ --- default_pg_version: 17 +default_pg_port: 5432 + noobient_pg_initdb_ok_str: 'Initializing database ... OK' noobient_pg_initdb_exists_str: 'Data directory is not empty!' +noobient_pg_user: 'postgres' +noobient_pg_group: "{{ noobient_pg_user }}" + eff_pg_unit: "postgresql{% if ansible_os_family == 'RedHat' %}-{{ eff_pg_version }}{% endif %}.service" eff_pg_enabled: "{% if enabled is defined %}{{ enabled | bool }}{% else %}false{% endif %}" +eff_pg_port: "{% if port is defined and port | string | length %}{{ port }}{% else %}{{ default_pg_port }}{% endif %}"