postgresql/tasks/Debian/install.yaml
2023-11-22 13:17:00 +03:00

91 lines
2.7 KiB
YAML

- name: Install apt-transport-https and gnupg
apt:
name:
- apt-transport-https
- gnupg
update_cache: yes
state: present
- 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 deps packages
apt:
name: "{{ postgresql_deps_packages }}"
state: present
update_cache: yes
- 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: Unmask PostgreSQL meta unit
systemd:
daemon_reload: true
name: "postgresql"
enabled: true
masked: no
- 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)