Skip to content

Commit 9e07c23

Browse files
oyalecesarlr
authored andcommitted
fix: dynamically get nginx paths
1 parent 0944f99 commit 9e07c23

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

tasks/compile.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@
77
path: "~/ModSecurity"
88
register: modsecurity_folder
99

10-
- name: Set nginx_modules_location if not already set
10+
- name: Get Nginx modules location
11+
shell: nginx -V 2>&1 | grep "configure arguments:" | sed -e 's/.*--modules-path=\([^ ]*\).*/\1/'
12+
register: _nginx_modules_location
13+
changed_when: false
14+
when: nginx_modules_location is not defined
15+
16+
- name: Set variable nginx_modules_location
1117
set_fact:
12-
nginx_modules_location: "{{ nginx_conf_dir }}/modules"
18+
nginx_modules_location: "{{ _nginx_modules_location.stdout }}"
1319
when: nginx_modules_location is not defined
1420

1521
- name: Clear previous compilation
@@ -143,7 +149,7 @@
143149
- name: Copy ModSecurity-nginx to Nginx modules folder
144150
copy:
145151
src: "~/Nginx/nginx-{{ nginx_modsec3_crs3_nginx_version }}/objs/ngx_http_modsecurity_module.so"
146-
dest: "{{ nginx_modules_location }}"
152+
dest: "{{ nginx_modules_location }}/ngx_http_modsecurity_module.so"
147153
remote_src: yes
148154
when: not modsec3_nginx_present or nginx_modsec3_crs3_force_compile
149155

tasks/main.yml

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,41 @@
1313
state: present
1414
when: ansible_os_family == "RedHat"
1515

16-
- name: run Nginx selinux tasks
16+
- name: Save the current list of packages for Debian/Ubuntu
17+
shell: dpkg-query -l > /tmp/before.txt
18+
when: ansible_os_family == "Debian" and ( nginx_modsec3_crs3_keep is undefined or not nginx_modsec3_crs3_keep )
19+
20+
- name: Save the current list of packages for RHEL/Centos
21+
shell: rpm -qa > /tmp/before.txt
22+
when: ansible_os_family == 'RedHat' and ( nginx_modsec3_crs3_keep is undefined or not nginx_modsec3_crs3_keep )
23+
24+
- name: Installing compiler dependencies for Debian/Ubuntu
25+
apt:
26+
name: "{{ nginx_modsec3_crs3_debian_compiler_reqs }}"
27+
state: present
28+
when: ansible_os_family == "Debian"
29+
30+
- name: Installing compiler dependencies for RHEL/Centos
31+
yum:
32+
name: "{{ nginx_modsec3_crs3_redhat_compiler_reqs }}"
33+
state: present
34+
when: ansible_os_family == "Redhat"
35+
36+
- name: Run Nginx SElinux tasks
1737
include_role:
1838
name: jdauphant.nginx
1939
tasks_from: selinux.yml
2040
allow_duplicates: yes
2141
when: ansible_selinux and ansible_selinux.status == "enabled"
2242

23-
- name: run Nginx nginx offical repo tasks
43+
- name: Run Nginx official repo tasks
2444
include_role:
2545
name: jdauphant.nginx
2646
tasks_from: nginx-official-repo.yml
2747
allow_duplicates: yes
2848
when: nginx_official_repo == True
2949

30-
- name: run Nginx install packages tasks
50+
- name: Run Nginx install packages tasks
3151
include_role:
3252
name: jdauphant.nginx
3353
tasks_from: installation.packages.yml
@@ -63,12 +83,15 @@
6383
set_fact:
6484
nginx_modsec3_crs3_nginx_version: "{{ ansible_facts.packages.nginx[0].version.split('-')[0] }}"
6585

66-
- name: Compile ModSecurity3 , install OWAPS CRS3, and build nginx modules
67-
import_tasks: compile.yml
86+
- name: Get Nginx conf location
87+
shell: dirname $(nginx -V 2>&1 | grep "configure arguments:" | sed -e 's/.*--conf-path=\([^ ]*\).*/\1/')
88+
register: _nginx_conf_location
89+
changed_when: false
90+
when: nginx_conf_dir is not defined
6891

69-
- name: Set nginx_conf_dir if not already set
92+
- name: Set variable nginx_conf_dir
7093
set_fact:
71-
nginx_conf_dir: "/etc/nginx"
94+
nginx_conf_dir: "{{ _nginx_conf_location.stdout }}"
7295
when: nginx_conf_dir is not defined
7396

7497
- name: Check if ModSecurity3 is present

0 commit comments

Comments
 (0)