Skip to content

Commit ba092d0

Browse files
authored
Merge pull request #34 from nginxinc/(feature)/select-repositories
Implement support to select NGINX repository
2 parents aef307f + 8e3ca5e commit ba092d0

File tree

9 files changed

+108
-77
lines changed

9 files changed

+108
-77
lines changed

.travis.yml

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,73 @@ services:
55
env:
66
- distribution: centos
77
version: 6
8-
playbook: opensource
8+
playbook: basic
99
- distribution: centos
1010
version: 6
11-
playbook: template
11+
playbook: push
1212
- distribution: centos
1313
version: 6
14-
playbook: push
14+
playbook: stable
15+
- distribution: centos
16+
version: 6
17+
playbook: template
1518
- distribution: centos
1619
version: 7
17-
playbook: opensource
20+
playbook: basic
1821
- distribution: centos
1922
version: 7
2023
playbook: template
24+
- distribution: centos
25+
version: 7
26+
playbook: stable
2127
- distribution: centos
2228
version: 7
2329
playbook: push
2430
- distribution: debian
2531
version: jessie
26-
playbook: opensource
32+
playbook: basic
2733
- distribution: debian
2834
version: jessie
2935
playbook: template
36+
- distribution: debian
37+
version: jessie
38+
playbook: stable
3039
- distribution: debian
3140
version: jessie
3241
playbook: push
3342
- distribution: debian
3443
version: stretch
35-
playbook: opensource
44+
playbook: basic
3645
- distribution: debian
3746
version: stretch
3847
playbook: template
48+
- distribution: debian
49+
version: stretch
50+
playbook: stable
3951
- distribution: debian
4052
version: stretch
4153
playbook: push
4254
- distribution: ubuntu
4355
version: trusty
44-
playbook: opensource
56+
playbook: basic
4557
- distribution: ubuntu
4658
version: trusty
4759
playbook: template
60+
- distribution: ubuntu
61+
version: trusty
62+
playbook: stable
4863
- distribution: ubuntu
4964
version: trusty
5065
playbook: push
5166
- distribution: ubuntu
5267
version: xenial
53-
playbook: opensource
68+
playbook: basic
5469
- distribution: ubuntu
5570
version: xenial
5671
playbook: template
72+
- distribution: ubuntu
73+
version: xenial
74+
playbook: stable
5775
- distribution: ubuntu
5876
version: xenial
5977
playbook: push

README.md

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

87+
# Specify repository origin for NGINX Open Source.
88+
# Options are 'nginx_repository' or 'os_repository'.
89+
# Only works if 'type' is set to 'opensource'.
90+
# Default is nginx_repository.
91+
install_from: nginx_repository
92+
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+
87105
# Specify which branch of NGINX Open Source you want to install.
88106
# Options are 'mainline' or 'stable'.
107+
# Only works if 'install_from' is set to 'nginx_repository'.
89108
# Default is mainline.
90109
branch: mainline
91110

92-
# Install nginscript, perl, waf (NGINX Plus only), geoip, image-filter, rtmp and/or xslt modules.
111+
# Install NGINX JavaScript, Perl, ModSecurity WAF (NGINX Plus only), GeoIP, Image-Filter, RTMP Media Streaming, and/or XSLT modules.
93112
# Default is false.
94113
modules:
95114
njs: false

defaults/main.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,27 @@
44
# Default is 'opensource'.
55
type: opensource
66

7+
# Specify repository origin for NGINX Open Source.
8+
# Options are 'nginx_repository' or 'os_repository'.
9+
# Only works if 'type' is set to 'opensource'.
10+
# Default is nginx_repository.
11+
install_from: nginx_repository
12+
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/{{ (branch == 'mainline') | ternary('mainline/','') }}{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx
19+
- deb-src https://nginx.org/packages/{{ (branch == 'mainline') | ternary('mainline/','') }}{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx
20+
redhat:
21+
- https://nginx.org/packages/{{ (branch == 'mainline') | ternary('mainline/','') }}{{ (ansible_distribution == "RedHat") | ternary('rhel/', 'centos/') }}{{ ansible_distribution_major_version|int }}/$basearch/
22+
suse:
23+
- https://nginx.org/packages/{{ (branch == 'mainline') | ternary('mainline/','') }}sles/12
24+
725
# Specify which branch of NGINX Open Source you want to install.
826
# Options are 'mainline' or 'stable'.
27+
# Only works if 'install_from' is set to 'nginx_repository'.
928
# Default is mainline.
1029
branch: mainline
1130

tasks/opensource/install-oss.yml

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
11
---
2-
- import_tasks: setup-debian.yml
3-
when: ansible_os_family == "Debian"
2+
- name: ""
3+
block:
44

5-
- import_tasks: setup-redhat.yml
6-
when: ansible_os_family == "RedHat"
5+
- import_tasks: setup-debian.yml
6+
when: ansible_os_family == "Debian"
77

8-
- import_tasks: setup-suse.yml
9-
when: ansible_os_family == "Suse"
8+
- import_tasks: setup-redhat.yml
9+
when: ansible_os_family == "RedHat"
1010

11-
- import_tasks: setup-freebsd.yml
12-
when: ansible_os_family == "FreeBSD"
11+
- import_tasks: setup-suse.yml
12+
when: ansible_os_family == "Suse"
1313

14-
- name: "(Install: Debian/Ubuntu/CentOS/RedHat) Install NGINX"
15-
package:
16-
name: nginx
17-
state: present
18-
when: ansible_os_family != "FreeBSD"
19-
notify: "(Handler: All OSs) Start NGINX"
14+
- import_tasks: setup-freebsd.yml
15+
when: ansible_os_family == "FreeBSD"
2016

21-
- name: "(Install: FreeBSD) Install NGINX"
22-
portinstall:
17+
- name: "(Install: Debian/Ubuntu/CentOS/RedHat) Install NGINX"
18+
package:
19+
name: nginx
20+
state: present
21+
when: ansible_os_family != "FreeBSD"
22+
notify: "(Handler: All OSs) Start NGINX"
23+
24+
- name: "(Install: FreeBSD) Install NGINX"
25+
portinstall:
26+
name: nginx
27+
state: present
28+
when: ansible_os_family == "FreeBSD"
29+
notify: "(Handler: All OSs) Start NGINX"
30+
31+
when: install_from == "nginx_repository"
32+
33+
- name: "(Install: Debian/Ubuntu/CentOS/RedHat/FreeBSD) Install NGINX"
34+
package:
2335
name: nginx
2436
state: present
25-
when: ansible_os_family == "FreeBSD"
37+
when: install_from == "os_repository"
2638
notify: "(Handler: All OSs) Start NGINX"

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 }}"

tests/playbooks/nginx-stable.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
- hosts: localhost
3+
become: true
4+
remote_user: root
5+
roles:
6+
- ansible-role-nginx
7+
vars:
8+
branch: stable

0 commit comments

Comments
 (0)