|
3 | 3 | # Using the rpm URL format of the yum module causes Ansible to download the rpm
|
4 | 4 | # every time to check whether it's installed, so, don't do that.
|
5 | 5 | - name: Check pgdg repository package (RedHat)
|
6 |
| - yum: name=pgdg-{{ postgresql_pgdg_dists[ansible_distribution] }}{{ postgresql_version | replace('.', '') }} |
7 |
| - register: repo_pkg_installed |
| 6 | + yum: |
| 7 | + name: "pgdg-{{ postgresql_pgdg_dists[ansible_distribution] }}{{ postgresql_version | replace('.', '') }}" |
| 8 | + register: __postgresql_repo_pkg_installed_result |
8 | 9 | ignore_errors: yes
|
9 | 10 |
|
10 |
| -# URLs for Fedora look like: |
11 |
| -# http://yum.postgresql.org/<pg_version>/fedora/fedora-<os_major_version>-<arch>/pgdg-fedora<pg_version_without_period>-<pg_version>-<rpm_release_version>.noarch.rpm |
| 11 | +# URLs for Fedora look like (line split for linting purposes): |
| 12 | +# http://yum.postgresql.org/<pg_version>/fedora/fedora-<os_major_version>-<arch> |
| 13 | +# /pgdg-fedora<pg_version_without_period>-<pg_version>-<rpm_release_version>.noarch.rpm |
12 | 14 | # URLs for RedHat and all derivatives look like:
|
13 |
| -# http://yum.postgresql.org/<pg_version>/redhat/rhel-<os_major_version>-<arch>/pgdg-<dist><pg_version_without_period>-<pg_version>-<rpm_release_version>.noarch.rpm |
| 15 | +# http://yum.postgresql.org/<pg_version>/redhat/rhel-<os_major_version>-<arch> |
| 16 | +# /pgdg-<dist><pg_version_without_period>-<pg_version>-<rpm_release_version>.noarch.rpm |
14 | 17 |
|
15 | 18 | # There's no direct way to determine the latest pacakge, so we have to use a
|
16 | 19 | # helper script to parse the directory list and figure it out.
|
17 | 20 | - name: Determine latest pgdg repository package (RedHat)
|
18 |
| - script: get_repo_rpm_release.py http://yum.postgresql.org/{{ postgresql_version }}/{{ postgresql_pgdg_families[ansible_distribution] | default("redhat") }}/{{ postgresql_pgdg_shortfamilies[ansible_distribution] | default("rhel") }}-{{ ansible_distribution_major_version }}-{{ ansible_architecture }}/ {{ postgresql_pgdg_dists[ansible_distribution] }} |
19 |
| - register: pgdg_repo_pkg_name |
20 |
| - when: repo_pkg_installed.failed is defined and repo_pkg_installed.failed |
| 21 | + script: >- |
| 22 | + get_repo_rpm_release.py |
| 23 | + http://yum.postgresql.org/{{ postgresql_version }}/{{ postgresql_pgdg_families[ansible_distribution] |
| 24 | + | default("redhat") }}/{{ postgresql_pgdg_shortfamilies[ansible_distribution] |
| 25 | + | default("rhel") }}-{{ ansible_distribution_major_version }}-{{ ansible_architecture }}/ {{ |
| 26 | + postgresql_pgdg_dists[ansible_distribution] |
| 27 | + }} |
| 28 | + register: __postgresql_pgdg_repo_pkg_name_result |
| 29 | + when: __postgresql_repo_pkg_installed_result is failed |
21 | 30 |
|
22 | 31 | - name: Install pgdg repository package (RedHat)
|
23 |
| - yum: name=http://yum.postgresql.org/{{ postgresql_version }}/{{ postgresql_pgdg_families[ansible_distribution] | default("redhat") }}/{{ postgresql_pgdg_shortfamilies[ansible_distribution] | default("rhel") }}-{{ ansible_distribution_major_version }}-{{ ansible_architecture }}/{{ pgdg_repo_pkg_name.stdout.strip() }} |
24 |
| - when: repo_pkg_installed.failed is defined and repo_pkg_installed.failed |
| 32 | + yum: |
| 33 | + name: >- |
| 34 | + http://yum.postgresql.org/{{ postgresql_version }}/{{ postgresql_pgdg_families[ansible_distribution] |
| 35 | + | default("redhat") }}/{{ postgresql_pgdg_shortfamilies[ansible_distribution] |
| 36 | + | default("rhel") }}-{{ ansible_distribution_major_version }}-{{ ansible_architecture }}/{{ |
| 37 | + __postgresql_pgdg_repo_pkg_name_result.stdout.strip() |
| 38 | + }} |
| 39 | + register: __postgresql_yum_result |
| 40 | + until: __postgresql_yum_result is succeeded |
| 41 | + retries: 5 |
| 42 | + delay: 5 |
| 43 | + when: __postgresql_repo_pkg_installed_result is failed |
25 | 44 |
|
26 | 45 | - name: Install PostgreSQL (RedHat)
|
27 |
| - yum: name=postgresql{{ postgresql_version | replace('.', '') }}-server |
| 46 | + yum: |
| 47 | + name: postgresql{{ postgresql_version | replace('.', '') }}-server |
28 | 48 |
|
29 | 49 | - name: Check for pgdata directory
|
30 |
| - stat: path={{ postgresql_pgdata }}/base |
| 50 | + stat: |
| 51 | + path: "{{ postgresql_pgdata }}/base" |
31 | 52 | register: pgdata_stat
|
32 | 53 | failed_when: false
|
33 | 54 |
|
34 | 55 | - name: Initialize database (RedHat < 7)
|
35 | 56 | command: /sbin/service postgresql-{{ postgresql_version }} initdb
|
36 |
| - when: ansible_distribution_major_version | int < 7 and (pgdata_stat.stat.isdir is not defined or not pgdata_stat.stat.isdir) |
| 57 | + args: |
| 58 | + warn: false # Use of /sbin/service is valid here, ignore lint error |
| 59 | + when: >- |
| 60 | + ansible_distribution_major_version | int < 7 |
| 61 | + and (pgdata_stat.stat.isdir is not defined or not pgdata_stat.stat.isdir) |
37 | 62 |
|
38 | 63 | - name: Initialize database (RedHat >= 7)
|
39 |
| - command: /usr/pgsql-{{ postgresql_version }}/bin/postgresql{{ postgresql_version | replace('.', '') }}-setup initdb |
40 |
| - when: ansible_distribution_major_version | int >= 7 and (pgdata_stat.stat.isdir is not defined or not pgdata_stat.stat.isdir) |
| 64 | + command: >- |
| 65 | + /usr/pgsql-{{ postgresql_version }}/bin/postgresql{{ |
| 66 | + '-' if postgresql_version is version_compare('10', '>=') else '' }}{{ |
| 67 | + postgresql_version | replace('.', '') }}-setup initdb |
| 68 | + when: >- |
| 69 | + ansible_distribution_major_version | int >= 7 |
| 70 | + and (pgdata_stat.stat.isdir is not defined or not pgdata_stat.stat.isdir) |
0 commit comments