Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use FQCN #269

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: restart postgresql
service:
ansible.builtin.service:
name: "{{ postgresql_daemon }}"
state: "{{ postgresql_restarted_state }}"
sleep: 5
6 changes: 3 additions & 3 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Configure global settings.
lineinfile:
ansible.builtin.lineinfile:
dest: "{{ postgresql_config_path }}/postgresql.conf"
regexp: "^#?{{ item.option }}.+$"
line: "{{ item.option }} = '{{ item.value }}'"
Expand All @@ -10,7 +10,7 @@
notify: restart postgresql

- name: Configure host based authentication (if entries are configured).
template:
ansible.builtin.template:
src: "pg_hba.conf.j2"
dest: "{{ postgresql_config_path }}/pg_hba.conf"
owner: "{{ postgresql_user }}"
Expand All @@ -20,7 +20,7 @@
when: postgresql_hba_entries | length > 0

- name: Ensure PostgreSQL unix socket dirs exist.
file:
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: "{{ postgresql_user }}"
Expand Down
2 changes: 1 addition & 1 deletion tasks/databases.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Ensure PostgreSQL databases are present.
postgresql_db:
community.postgresql.postgresql_db:
name: "{{ item.name }}"
lc_collate: "{{ item.lc_collate | default('en_US.UTF-8') }}"
lc_ctype: "{{ item.lc_ctype | default('en_US.UTF-8') }}"
Expand Down
10 changes: 5 additions & 5 deletions tasks/initialize.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
---
- name: Set PostgreSQL environment variables.
template:
ansible.builtin.template:
src: postgres.sh.j2
dest: /etc/profile.d/postgres.sh
mode: 0644
notify: restart postgresql

- name: Ensure PostgreSQL data directory exists.
file:
ansible.builtin.file:
path: "{{ postgresql_data_dir }}"
owner: "{{ postgresql_user }}"
group: "{{ postgresql_group }}"
state: directory
mode: 0700

- name: Check if PostgreSQL database is initialized.
stat:
ansible.builtin.stat:
path: "{{ postgresql_data_dir }}/PG_VERSION"
register: pgdata_dir_version

- name: Ensure PostgreSQL database is initialized.
command: "{{ postgresql_bin_path }}/initdb -D {{ postgresql_data_dir }}"
ansible.builtin.command: "{{ postgresql_bin_path }}/initdb -D {{ postgresql_data_dir }}"
when: not pgdata_dir_version.stat.exists
become: true
become_user: "{{ postgresql_user }}"
Expand All @@ -29,7 +29,7 @@
ansible_ssh_pipelining: true

- name: Ensure PostgreSQL log directory exists.
file:
ansible.builtin.file:
path: "{{ postgresql_effective_log_dir }}"
owner: "{{ postgresql_user }}"
group: "{{ postgresql_group }}"
Expand Down
20 changes: 10 additions & 10 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
---
# Variable configuration.
- include_tasks: variables.yml
- ansible.builtin.include_tasks: variables.yml

# Setup/install tasks.
- include_tasks: setup-Archlinux.yml
- ansible.builtin.include_tasks: setup-Archlinux.yml
when: ansible_os_family == 'Archlinux'

- include_tasks: setup-Debian.yml
- ansible.builtin.include_tasks: setup-Debian.yml
when: ansible_os_family == 'Debian'

- include_tasks: setup-RedHat.yml
- ansible.builtin.include_tasks: setup-RedHat.yml
when: ansible_os_family == 'RedHat'

- include_tasks: initialize.yml
- include_tasks: configure.yml
- ansible.builtin.include_tasks: initialize.yml
- ansible.builtin.include_tasks: configure.yml

- name: Ensure PostgreSQL is started and enabled on boot.
service:
ansible.builtin.service:
name: "{{ postgresql_daemon }}"
state: "{{ postgresql_service_state }}"
enabled: "{{ postgresql_service_enabled }}"

# Configure PostgreSQL.
- import_tasks: users.yml
- import_tasks: databases.yml
- import_tasks: users_props.yml
- ansible.builtin.import_tasks: users.yml
- ansible.builtin.import_tasks: databases.yml
- ansible.builtin.import_tasks: users_props.yml
8 changes: 4 additions & 4 deletions tasks/setup-Archlinux.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
---
- name: Ensure PostgreSQL Python libraries are installed.
pacman:
community.general.pacman:
name: "{{ postgresql_python_library }}"
state: present

- name: Ensure PostgreSQL packages are installed.
pacman:
community.general.pacman:
name: "{{ postgresql_packages }}"
state: present

- name: Ensure all configured locales are present.
locale_gen: "name={{ item }} state=present"
community.general.locale_gen: "name={{ item }} state=present"
with_items: "{{ postgresql_locales }}"
register: locale_gen_result

- name: Force-restart PostgreSQL after new locales are generated.
systemd:
ansible.builtin.systemd_service:
name: "{{ postgresql_daemon }}"
state: restarted
when: locale_gen_result.changed
8 changes: 4 additions & 4 deletions tasks/setup-Debian.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
---
- name: Ensure PostgreSQL Python libraries are installed.
apt:
ansible.builtin.apt:
name: "{{ postgresql_python_library }}"
state: present

- name: Ensure PostgreSQL packages are installed.
apt:
ansible.builtin.apt:
name: "{{ postgresql_packages }}"
state: present

- name: Ensure all configured locales are present.
locale_gen: "name={{ item }} state=present"
community.general.locale_gen: "name={{ item }} state=present"
with_items: "{{ postgresql_locales }}"
register: locale_gen_result

- name: Force-restart PostgreSQL after new locales are generated.
service:
ansible.builtin.service:
name: "{{ postgresql_daemon }}"
state: restarted
when: locale_gen_result.changed
4 changes: 2 additions & 2 deletions tasks/setup-RedHat.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Ensure PostgreSQL packages are installed.
yum:
ansible.builtin.yum: # FIXME: this should be migrated to ansible.builtin.dnf
name: "{{ postgresql_packages }}"
state: present
enablerepo: "{{ postgresql_enablerepo | default(omit, true) }}"
Expand All @@ -10,7 +10,7 @@
exclude: python-unversioned-command

- name: Ensure PostgreSQL Python libraries are installed.
yum:
ansible.builtin.yum: # FIXME: this should be migrated to ansible.builtin.dnf
name: "{{ postgresql_python_library }}"
state: present
enablerepo: "{{ postgresql_enablerepo | default(omit, true) }}"
2 changes: 1 addition & 1 deletion tasks/users.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Ensure PostgreSQL users are present.
postgresql_user:
community.postgresql.postgresql_user:
name: "{{ item.name }}"
password: "{{ item.password | default(omit) }}"
login_host: "{{ item.login_host | default('localhost') }}"
Expand Down
6 changes: 3 additions & 3 deletions tasks/users_props.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Ensure PostgreSQL users are configured correctly.
postgresql_user:
community.postgresql.postgresql_user:
name: "{{ item.name }}"
password: "{{ item.password | default(omit) }}"
encrypted: "{{ item.encrypted | default(omit) }}"
Expand All @@ -23,13 +23,13 @@
PGOPTIONS: "{{ (postgresql_auth_method == 'scram-sha-256') | ternary('-c password_encryption=scram-sha-256', '') }}"

- name: Ensure PostgreSQL users do not use deprecated privileges settings
debug:
ansible.builtin.debug:
msg "Postgresql user {{ item.name }} uses deprecated privileges settings. See https://github.com/geerlingguy/ansible-role-postgresql/issues/254"

Check warning on line 27 in tasks/users_props.yml

View workflow job for this annotation

GitHub Actions / Lint

27:121 [line-length] line too long (148 > 120 characters)
with_items: "{{ postgresql_users }}"
when: item.priv is defined

- name: Ensure PostgreSQL users privileges are configured correctly.
postgresql_privs:
community.postgresql.postgresql_privs:
roles: "{{ item.roles }}"
db: "{{ item.db }}"
privs: "{{ item.privs | default(omit) }}"
Expand Down
28 changes: 14 additions & 14 deletions tasks/variables.yml
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
---
# Variable configuration.
- name: Include OS-specific variables (Debian).
include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
ansible.builtin.include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
when: ansible_os_family == 'Debian'

- name: Include OS-specific variables (RedHat).
include_vars: "{{ ansible_os_family }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
ansible.builtin.include_vars: "{{ ansible_os_family }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
when:
- ansible_os_family == 'RedHat'
- ansible_distribution != 'Fedora'
- ansible_distribution != 'Amazon'

- name: Include OS-specific variables (Amazon).
include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
ansible.builtin.include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
when: ansible_distribution == 'Amazon'

- name: Include OS-specific variables (Fedora).
include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
ansible.builtin.include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
when: ansible_distribution == 'Fedora'

- name: Define postgresql_packages.
set_fact:
ansible.builtin.set_fact:
postgresql_packages: "{{ __postgresql_packages | list }}"
when: postgresql_packages is not defined

- name: Define postgresql_version.
set_fact:
ansible.builtin.set_fact:
postgresql_version: "{{ __postgresql_version }}"
when: postgresql_version is not defined

- name: Define postgresql_daemon.
set_fact:
ansible.builtin.set_fact:
postgresql_daemon: "{{ __postgresql_daemon }}"
when: postgresql_daemon is not defined

- name: Define postgresql_data_dir.
set_fact:
ansible.builtin.set_fact:
postgresql_data_dir: "{{ __postgresql_data_dir }}"
when: postgresql_data_dir is not defined

- name: Define postgresql_bin_path.
set_fact:
ansible.builtin.set_fact:
postgresql_bin_path: "{{ __postgresql_bin_path }}"
when: postgresql_bin_path is not defined

- name: Define postgresql_config_path.
set_fact:
ansible.builtin.set_fact:
postgresql_config_path: "{{ __postgresql_config_path }}"
when: postgresql_config_path is not defined

- name: Define postgresql_unix_socket_directories_mode.
set_fact:
ansible.builtin.set_fact:
postgresql_unix_socket_directories_mode: >-
{{ __postgresql_unix_socket_directories_mode | default('02775') }}
when: postgresql_unix_socket_directories_mode is not defined

- name: Define postgresql_log_dir.
set_fact:
ansible.builtin.set_fact:
# postgresql_global_config_options is an array but its keys are unique, so it can be converted to dict,
# to easily get the value under the 'log_directory' key
postgresql_log_dir: "{{ (postgresql_global_config_options | items2dict(key_name='option', value_name='value')).log_directory }}"

Check warning on line 62 in tasks/variables.yml

View workflow job for this annotation

GitHub Actions / Lint

62:121 [line-length] line too long (132 > 120 characters)

- name: Define postgresql_effective_log_dir, if postgresql_log_dir is absolute
set_fact:
ansible.builtin.set_fact:
postgresql_effective_log_dir: '{{ postgresql_log_dir }}'
when: postgresql_log_dir is match("/")

- name: Define postgresql_effective_log_dir, if postgresql_log_dir is relative
set_fact:
ansible.builtin.set_fact:
postgresql_effective_log_dir: '{{ postgresql_data_dir }}/{{ postgresql_log_dir }}'
when: postgresql_log_dir is not match("/")
Loading