Skip to content

Commit 1507fbe

Browse files
authored
Merge pull request #22 from galaxyproject/el-repo-changes
Additional fixes for yum repo changes upstream
2 parents ea4135d + d3c29ac commit 1507fbe

File tree

2 files changed

+34
-40
lines changed

2 files changed

+34
-40
lines changed

tasks/redhat.yml

+30-31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
---
22

3+
- name: Set PostgreSQL dotless version fact
4+
set_fact:
5+
__postgresql_version_dotless: "{{ postgresql_version | replace('.', '') }}"
6+
__postgresql_command_sep: "{{ postgresql_version is version('10', '>=') | ternary('-', '') }}"
7+
38
# Using the rpm URL format of the yum module causes Ansible to download the rpm
49
# every time to check whether it's installed, so, don't do that.
510
- name: Check pgdg repository package (RedHat)
@@ -8,43 +13,38 @@
813
register: __postgresql_repo_pkg_installed_result
914
ignore_errors: yes
1015

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
14-
# URLs for RedHat and all derivatives look like:
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
17-
18-
# There's no direct way to determine the latest pacakge, so we have to use a
19-
# helper script to parse the directory list and figure it out.
20-
- name: Determine latest pgdg repository package (RedHat)
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
30-
3116
- name: Install pgdg repository package (RedHat)
3217
yum:
3318
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-
}}
19+
https://download.postgresql.org/pub/repos/yum/reporpms/{{ postgresql_pgdg_shortfamilies[ansible_distribution]
20+
| default("EL") }}-{{ ansible_distribution_major_version }}-{{ ansible_architecture }}/pgdg-{{
21+
postgresql_pgdg_families[ansible_distribution] | default("redhat") }}-repo-latest.noarch.rpm
3922
register: __postgresql_yum_result
4023
until: __postgresql_yum_result is succeeded
4124
retries: 5
4225
delay: 5
4326
when: __postgresql_repo_pkg_installed_result is failed
4427

28+
#- name: Collect installed repos
29+
# yum:
30+
# list: repos
31+
# until: __postgresql_yum_repolist_result is succeeded
32+
# retries: 5
33+
# delay: 5
34+
# register: __postgresql_yum_repolist_result
35+
36+
# Not supported (and no good workaround) until there is a solution for https://github.com/ansible/ansible/issues/41178
37+
#- name: Ensure that only the desired PostgreSQL version's repo is enabled
38+
# yum_repository:
39+
# name: item.repoid
40+
# enabled: "{{ (item.repoid == 'pgdg' ~ __postgresql_version_dotless) if item.repoid.startswith('pgdg') else item.state == 'enabled' }}"
41+
# # "{{ __postgresql_yum_repolist_result.results | selectattr('repoid', 'startswith', 'pgdg') | list }}" would be nice
42+
# # here but alas there is no `startswith` test
43+
# loop: "{{ __postgresql_yum_repolist_result.results }}"
44+
4545
- name: Install PostgreSQL (RedHat)
4646
yum:
47-
name: postgresql{{ postgresql_version | replace('.', '') }}-server
47+
name: postgresql{{ __postgresql_version_dotless }}-server
4848

4949
- name: Check for pgdata directory
5050
stat:
@@ -57,14 +57,13 @@
5757
args:
5858
warn: false # Use of /sbin/service is valid here, ignore lint error
5959
when: >-
60-
ansible_distribution_major_version | int < 7
60+
ansible_distribution_major_version is version(7, '<')
6161
and (pgdata_stat.stat.isdir is not defined or not pgdata_stat.stat.isdir)
6262

6363
- name: Initialize database (RedHat >= 7)
6464
command: >-
65-
/usr/pgsql-{{ postgresql_version }}/bin/postgresql{{
66-
'-' if postgresql_version is version_compare('10', '>=') else '' }}{{
67-
postgresql_version | replace('.', '') }}-setup initdb
65+
/usr/pgsql-{{ postgresql_version }}/bin/postgresql{{ __postgresql_command_sep }}{{
66+
__postgresql_version_dotless }}-setup initdb
6867
when: >-
69-
ansible_distribution_major_version | int >= 7
68+
ansible_distribution_major_version is version(7, '>=')
7069
and (pgdata_stat.stat.isdir is not defined or not pgdata_stat.stat.isdir)

vars/main.yml

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
---
22

3-
# maps ansible_distribution to the pgdg repository package name
4-
postgresql_pgdg_dists:
5-
RedHat: redhat
6-
CentOS: centos
7-
Scientific: sl
8-
SLC: sl
9-
OracleLinux: oraclelinux
10-
3+
# maps ansible_* to the pgdg repository package name
114
postgresql_pgdg_families:
5+
#default: redhat
126
Fedora: fedora
137

148
postgresql_pgdg_shortfamilies:
15-
Fedora: fedora
9+
#default: EL
10+
Fedora: F

0 commit comments

Comments
 (0)