Skip to content

Commit 4037b19

Browse files
committed
Refactor repository into a variable
1 parent 98974fb commit 4037b19

File tree

5 files changed

+34
-53
lines changed

5 files changed

+34
-53
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,24 @@ This role has multiple variables. The defaults for all these variables are the f
8484
# Default is 'opensource'.
8585
type: opensource
8686

87-
# Specify source respository for NGINX Open Source.
87+
# Specify repository origin for NGINX Open Source.
8888
# Options are 'nginx_repository' or 'os_repository'.
89+
# Only works if 'type' is set to 'opensource'.
8990
# Default is nginx_repository.
9091
install_from: nginx_repository
9192

93+
# Specify source repository for NGINX Open Source.
94+
# Only works if 'install_from' is set to 'nginx_repository'.
95+
# Defaults are the official NGINX repositories.
96+
nginx_repository:
97+
debian:
98+
- 'deb https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx'
99+
- 'deb-src https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx'
100+
redhat:
101+
- https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}{{ (ansible_distribution == "RedHat") | ternary('rhel/', 'centos/') }}{{ ansible_distribution_major_version|int }}/$basearch/
102+
suse:
103+
- https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}sles/12
104+
92105
# Specify which branch of NGINX Open Source you want to install.
93106
# Options are 'mainline' or 'stable'.
94107
# Only works if 'install_from' is set to 'nginx_repository'.

defaults/main.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,24 @@
44
# Default is 'opensource'.
55
type: opensource
66

7-
# Specify source respository for NGINX Open Source.
7+
# Specify repository origin for NGINX Open Source.
88
# Options are 'nginx_repository' or 'os_repository'.
9+
# Only works if 'type' is set to 'opensource'.
910
# Default is nginx_repository.
1011
install_from: nginx_repository
1112

13+
# Specify source repository for NGINX Open Source.
14+
# Only works if 'install_from' is set to 'nginx_repository'.
15+
# Defaults are the official NGINX repositories.
16+
nginx_repository:
17+
debian:
18+
- 'deb https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx'
19+
- 'deb-src https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx'
20+
redhat:
21+
- https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}{{ (ansible_distribution == "RedHat") | ternary('rhel/', 'centos/') }}{{ ansible_distribution_major_version|int }}/$basearch/
22+
suse:
23+
- https://nginx.org/packages/{{ "mainline/" if branch == "mainline" }}sles/12
24+
1225
# Specify which branch of NGINX Open Source you want to install.
1326
# Options are 'mainline' or 'stable'.
1427
# Only works if 'install_from' is set to 'nginx_repository'.

tasks/opensource/setup-debian.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
---
2-
- name: "(Install: Debian/Ubuntu) Add Mainline NGINX Repository"
2+
- name: "(Install: Debian/Ubuntu) Add NGINX Repository"
33
apt_repository:
44
repo: "{{ item }}"
55
with_items:
6-
- deb https://nginx.org/packages/mainline/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx
7-
- deb-src https://nginx.org/packages/mainline/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx
8-
when: branch == "mainline"
9-
10-
- name: "(Install: Debian/Ubuntu) Add Stable NGINX Repository"
11-
apt_repository:
12-
repo: "{{ item }}"
13-
with_items:
14-
- deb https://nginx.org/packages/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx
15-
- deb-src https://nginx.org/packages/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx
16-
when: branch == "stable"
6+
- "{{ nginx_repository.debian }}"

tasks/opensource/setup-redhat.yml

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,8 @@
11
---
2-
- name: "(Install: RedHat) Add Mainline NGINX Repository"
2+
- name: "(Install: CentOS/RedHat) Add NGINX Repository"
33
yum_repository:
44
name: nginx
5-
baseurl: https://nginx.org/packages/mainline/rhel/{{ ansible_distribution_major_version|int }}/$basearch/
5+
baseurl: "{{ nginx_repository.redhat }}"
66
description: NGINX Repository
77
enabled: yes
88
gpgcheck: yes
9-
when: branch == "mainline" and ansible_distribution == "RedHat"
10-
11-
- name: "(Install: CentOS) Add Mainline NGINX Repository"
12-
yum_repository:
13-
name: nginx
14-
baseurl: https://nginx.org/packages/mainline/centos/{{ ansible_distribution_major_version|int }}/$basearch/
15-
description: NGINX Repository
16-
enabled: yes
17-
gpgcheck: yes
18-
when: branch == "mainline" and ansible_distribution == "CentOS"
19-
20-
- name: "(Install: RedHat) Add Stable NGINX Repository"
21-
yum_repository:
22-
name: nginx
23-
baseurl: https://nginx.org/packages/rhel/{{ ansible_distribution_major_version|int }}/$basearch/
24-
description: NGINX Repository
25-
enabled: yes
26-
gpgcheck: yes
27-
when: branch == "stable" and ansible_distribution == "RedHat"
28-
29-
- name: "(Install: CentOS) Add Stable NGINX Repository"
30-
yum_repository:
31-
name: nginx
32-
baseurl: https://nginx.org/packages/centos/{{ ansible_distribution_major_version|int }}/$basearch/
33-
description: NGINX Repository
34-
enabled: yes
35-
gpgcheck: yes
36-
when: branch == "stable" and ansible_distribution == "CentOS"

tasks/opensource/setup-suse.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
---
2-
- name: "(Install: SUSE) Add Mainline NGINX Repository"
2+
- name: "(Install: SUSE) Add NGINX Repository"
33
zypper_repository:
44
name: nginx
5-
repo: https://nginx.org/packages/mainline/sles/12
6-
when: branch == "mainline"
7-
8-
- name: "(Install: SUSE) Add Stable NGINX Repository"
9-
zypper_repository:
10-
name: nginx
11-
repo: https://nginx.org/packages/sles/12
12-
when: branch == "stable"
5+
repo: "{{ nginx_repository.suse }}"

0 commit comments

Comments
 (0)