Skip to content

Commit

Permalink
Port number option
Browse files Browse the repository at this point in the history
Fixes #7
  • Loading branch information
bviktor committed Nov 28, 2024
1 parent aecc0fa commit b19866c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -19,6 +20,7 @@ This role installs and configures PostgreSQL instances.
vars:
version: 16
enabled: true
port: 6789
```
## Return Values
Expand Down
21 changes: 21 additions & 0 deletions tasks/config.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
1 change: 1 addition & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
when: ansible_os_family == 'RedHat'

- include_tasks: systemd.yml
- include_tasks: config.yml
2 changes: 2 additions & 0 deletions tests/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
name: "{{ playbook_dir.split('/')[:-1] | last }}"
vars:
version: 16
enabled: true
port: 7777
6 changes: 6 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -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 %}"

0 comments on commit b19866c

Please sign in to comment.