postgresql/tasks/Debian/install.yaml

84 lines
2.5 KiB
YAML
Raw Normal View History

- name: Install apt-transport-https and gnupg
2023-02-09 21:49:13 +00:00
apt:
name:
- apt-transport-https
- gnupg
2023-02-09 21:49:13 +00:00
update_cache: yes
state: present
2023-02-09 21:49:13 +00:00
- name: Add gpg keys for PostgreSQL repo
ansible.builtin.apt_key:
url: "{{ item.url }}"
keyring: "{{ item.keyring }}"
loop: "{{ postgresql_apt_key }}"
2023-03-29 20:47:01 +00:00
when: postgresql_install_official_repo
2023-02-09 21:49:13 +00:00
- name: Add PostgreSQL repository
ansible.builtin.apt_repository:
repo: "{{ item.repo }}"
state: present
filename: "{{ item.filename }}"
update_cache: yes
2023-03-29 20:47:01 +00:00
loop: "{{ postgresql_apt_repository }}"
when: postgresql_install_official_repo
- name: Install deps packages
apt:
name: "{{ postgresql_deps_packages }}"
state: present
update_cache: yes
2023-03-29 20:47:01 +00:00
- 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
2023-02-09 21:49:13 +00:00
- 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
2023-02-10 11:34:38 +00:00
- name: Print installed PostgreSQL version
debug:
2023-02-09 21:49:13 +00:00
msg: "{{ ansible_facts.packages[postgresql_package_name][0]['version'] }}"
2023-02-10 11:34:38 +00:00
verbosity: 2
2023-02-09 21:49:13 +00:00
when: postgresql_installed_package is defined
- name: Mask PostgreSQL before install
ansible.builtin.systemd:
name: "{{ postgresql_unit_name }}"
masked: yes
2023-03-29 20:47:01 +00:00
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)
2023-02-09 21:49:13 +00:00
- 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
2023-03-29 20:47:01 +00:00
- ansible_facts.packages[postgresql_package_name][0]['version'] != (postgresql_version|string + "-" + postgresql_version_build|string)