postgresql/tasks/Debian/install.yaml
2023-03-29 23:47:01 +03:00

76 lines
2.4 KiB
YAML

- name: Install deps packages
apt:
name: "{{ postgresql_deps_packages }}"
state: present
update_cache: yes
- name: Add gpg keys for PostgreSQL repo
ansible.builtin.apt_key:
url: "{{ item.url }}"
keyring: "{{ item.keyring }}"
loop: "{{ postgresql_apt_key }}"
when: postgresql_install_official_repo
- name: Add PostgreSQL repository
ansible.builtin.apt_repository:
repo: "{{ item.repo }}"
state: present
filename: "{{ item.filename }}"
update_cache: yes
loop: "{{ postgresql_apt_repository }}"
when: postgresql_install_official_repo
- name: Install postgresql-common
apt:
name: postgresql-common
state: present
- name: Create dir createcluster.d
file:
path: /etc/postgresql-common/createcluster.d
state: directory
- name: Disable main cluster creation by default
copy:
dest: /etc/postgresql-common/createcluster.d/create-main-cluster.conf
content: |
create_main_cluster = false
- name: Gather packages
package_facts:
manager: auto
- name: Set fact about PostgreSQL package
set_fact:
postgresql_installed_package: "{{ ansible_facts.packages[postgresql_package_name][0]['name'] }}"
when: postgresql_package_name in ansible_facts.packages
- name: Print installed PostgreSQL version
debug:
msg: "{{ ansible_facts.packages[postgresql_package_name][0]['version'] }}"
verbosity: 2
when: postgresql_installed_package is defined
- name: Mask PostgreSQL before install
ansible.builtin.systemd:
name: "{{ postgresql_unit_name }}"
masked: yes
when: postgresql_package_name not in ansible_facts.packages or ansible_facts.packages[postgresql_package_name][0]['version'] != (postgresql_version|string + "-" + postgresql_version_build|string)
- name: "Install {{ postgresql_package_name }}-{{ postgresql_version }}-{{ postgresql_version_build }}"
apt:
name: "{{ postgresql_package }}"
update_cache: yes
register: postgresql_setup
when: postgresql_package_name not in ansible_facts.packages
- name: "Update {{ postgresql_package_name }}-{{ postgresql_version }}-{{ postgresql_version_build }}"
apt:
name: "{{ postgresql_package }}"
update_cache: yes
register: postgresql_update
notify: Restart PostgreSQL
when:
- postgresql_package_name in ansible_facts.packages
- ansible_facts.packages[postgresql_package_name][0]['version'] != (postgresql_version|string + "-" + postgresql_version_build|string)