Skip to content

Commit 27d9462

Browse files
vbotkaalessfg
authored andcommitted
Separate installation of Linux and BSD (#182)
* Added variable nginx_linux_families: ['Debian', 'RedHat', 'Suse'] * Added variable nginx_bsd_systems: ['FreeBSD', 'NetBSD', 'OpenBSD', 'DragonFlyBSD', 'HardenedBSD'] * Handler started only in "not ansible_check_mode" to avoid --check failure when service hes not been installed yet * Installation of Linux moved to install-oss-linux.yml * Installation of BSD moved to install-oss-bsd.yml * File setup-freebsd.yml deleted
1 parent 78c21d4 commit 27d9462

File tree

6 files changed

+153
-47
lines changed

6 files changed

+153
-47
lines changed

defaults/main.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ nginx_start: true
1010
# Print NGINX configuration file to terminal after executing playbook.
1111
nginx_debug_output: false
1212

13+
# Supported systems
14+
nginx_linux_families: ['Debian', 'RedHat', 'Suse']
15+
nginx_bsd_systems: ['FreeBSD', 'NetBSD', 'OpenBSD', 'DragonFlyBSD', 'HardenedBSD']
16+
1317
# Specify which type of NGINX you want to install.
1418
# Options are 'opensource' or 'plus'.
1519
# Default is 'opensource'.
@@ -50,6 +54,22 @@ nginx_repository:
5054
https://nginx.org/packages/{{ (nginx_branch == 'mainline')
5155
| ternary('mainline/', '') }}sles/{{ ansible_distribution_major_version }}
5256
57+
# Choose to install BSD packages or ports.
58+
# Options are True for packages or False for ports.
59+
# Default is True.
60+
nginx_bsd_install_packages: true
61+
62+
# Choose to update BSD ports collection.
63+
# Options are True for update or False for do not update.
64+
# Default is True.
65+
nginx_bsd_update_ports: true
66+
67+
# Choose to install packages built from BSD ports collection if
68+
# available.
69+
# Options are True for use packages or False for do not use packages.
70+
# Default is True.
71+
nginx_bsd_portinstall_use_packages: true
72+
5373
# Specify which branch of NGINX Open Source you want to install.
5474
# Options are 'mainline' or 'stable'.
5575
# Only works if 'install_from' is set to 'nginx_repository'.

handlers/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
name: nginx
1414
state: reloaded
1515

16-
when: nginx_start | bool
16+
when:
17+
- nginx_start | bool
18+
- not ansible_check_mode
1719

1820
- name: "(Handler: All OSs) Start NGINX Amplify Agent"
1921
service:

tasks/opensource/install-oss-bsd.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
- name: "(Install: FreeBSD) Update ports"
3+
block:
4+
5+
- name: "(Install: FreeBSD) Fetch Ports"
6+
command: portsnap fetch --interactive
7+
args:
8+
creates: /var/db/portsnap/INDEX
9+
10+
- name: "(Install: FreeBSD) Extract Ports"
11+
command: portsnap extract
12+
args:
13+
creates: /usr/ports
14+
15+
when:
16+
- ansible_system == 'FreeBSD'
17+
- nginx_bsd_update_ports
18+
19+
- name: "(Install: FreeBSD)"
20+
block:
21+
22+
- name: "(Install: FreeBSD) Install NGINX package"
23+
pkgng:
24+
name: "www/nginx{{ nginx_version | default('') }}"
25+
state: present
26+
when: nginx_bsd_install_packages
27+
notify: "(Handler: All OSs) Start NGINX"
28+
29+
- name: "(Install: FreeBSD) Install NGINX port"
30+
portinstall:
31+
name: "www/nginx{{ nginx_version | default('') }}"
32+
use_packages: "{{ nginx_bsd_portinstall_use_packages | default(omit) }}"
33+
state: present
34+
when: not nginx_bsd_install_packages
35+
notify: "(Handler: All OSs) Start NGINX"
36+
37+
when: ansible_system == 'FreeBSD'
38+
39+
- name: "(Install: OpenBSD)"
40+
block:
41+
42+
- name: "(Install: OpenBSD) Install NGINX package"
43+
openbsd_pkg:
44+
name: "nginx{{ nginx_version | default('') }}"
45+
build: false
46+
state: present
47+
when: nginx_bsd_install_packages
48+
notify: "(Handler: All OSs) Start NGINX"
49+
50+
- name: "(Install: OpenBSD) Install NGINX port"
51+
openbsd_pkg:
52+
name: "nginx{{ nginx_version | default('') }}"
53+
build: true
54+
state: present
55+
when: not nginx_bsd_install_packages
56+
notify: "(Handler: All OSs) Start NGINX"
57+
58+
when: ansible_system == 'OpenBSD'
59+
60+
- name: "(Install: NetBSD)"
61+
block:
62+
63+
- name: "(Install: NetBSD) Install NGINX package"
64+
command: "pkg_add www/nginx{{ nginx_version | default('') }}"
65+
when: nginx_bsd_install_packages
66+
notify: "(Handler: All OSs) Start NGINX"
67+
68+
- name: "(Install: NetBSD) Install NGINX port"
69+
fail:
70+
msg: "{{ ansible_system }} Install NGINX port not implemented."
71+
when: not nginx_bsd_install_packages
72+
73+
when: ansible_system == 'NetBSD'
74+
75+
- name: "(Install: DragonFlyBSD)"
76+
block:
77+
78+
- name: "(Install: DragonFlyBSD) Install NGINX package"
79+
command: "pkg install www/nginx{{ nginx_version | default('') }}"
80+
when: nginx_bsd_install_packages
81+
notify: "(Handler: All OSs) Start NGINX"
82+
83+
- name: "(Install: DragonFlyBSD) Install NGINX port"
84+
fail:
85+
msg: "{{ ansible_system }} Install NGINX port not implemented."
86+
when: not nginx_bsd_install_packages
87+
88+
when: ansible_system == 'DragonFlyBSD'
89+
90+
- name: "(Install: HardenedBSD)"
91+
block:
92+
93+
- name: "(Install: HardenedBSD) Install NGINX package"
94+
command: "pkg install www/nginx{{ nginx_version | default('') }}"
95+
when: nginx_bsd_install_packages
96+
notify: "(Handler: All OSs) Start NGINX"
97+
98+
- name: "(Install: HardenedBSD) Install NGINX port"
99+
fail:
100+
msg: "{{ ansible_system }} Install NGINX port not implemented."
101+
when: not nginx_bsd_install_packages
102+
103+
when: ansible_system == 'HardenedBSD'
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
- name: "(Install: Linux) Configure NGINX repo"
3+
block:
4+
5+
- import_tasks: setup-debian.yml
6+
when: ansible_os_family == "Debian"
7+
8+
- import_tasks: setup-redhat.yml
9+
when: ansible_os_family == "RedHat"
10+
11+
- import_tasks: setup-suse.yml
12+
when: ansible_os_family == "Suse"
13+
14+
when: nginx_install_from == "nginx_repository"
15+
16+
- name: "(Install: Linux) Install NGINX package"
17+
package:
18+
name: "nginx{{ nginx_version | default('') }}"
19+
state: present
20+
when: ansible_os_family in nginx_linux_families
21+
notify: "(Handler: All OSs) Start NGINX"

tasks/opensource/install-oss.yml

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,8 @@
11
---
2-
- name: "(Install: Debian/Ubuntu/CentOS/RedHat/FreeBSD) Install NGINX"
3-
block:
2+
- name: "(Install: OSS Linux)"
3+
import_tasks: install-oss-linux.yml
4+
when: ansible_os_family in nginx_linux_families
45

5-
- import_tasks: setup-debian.yml
6-
when: ansible_os_family == "Debian"
7-
8-
- import_tasks: setup-redhat.yml
9-
when: ansible_os_family == "RedHat"
10-
11-
- import_tasks: setup-suse.yml
12-
when: ansible_os_family == "Suse"
13-
14-
- import_tasks: setup-freebsd.yml
15-
when: ansible_os_family == "FreeBSD"
16-
17-
- name: "(Install: Debian/Ubuntu/CentOS/RedHat) Install NGINX"
18-
package:
19-
name: "nginx{{ nginx_version | default('') }}"
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: nginx_install_from == "nginx_repository"
32-
33-
- name: "(Install: Debian/Ubuntu/CentOS/RedHat/FreeBSD) Install NGINX"
34-
package:
35-
name: "nginx{{ nginx_version | default('') }}"
36-
state: present
37-
when: nginx_install_from == "os_repository"
38-
notify: "(Handler: All OSs) Start NGINX"
6+
- name: "(Install: OSS BSD)"
7+
import_tasks: install-oss-bsd.yml
8+
when: ansible_system in nginx_bsd_systems

tasks/opensource/setup-freebsd.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)