2020-06-30 18:59:53 +02:00
|
|
|
---
|
2020-08-19 18:39:17 +02:00
|
|
|
- name: "(Setup: SELinux) Install Required CentOS/RHEL 6/7 Dependencies"
|
2020-06-30 18:59:53 +02:00
|
|
|
package:
|
2020-07-28 12:26:38 +02:00
|
|
|
name:
|
|
|
|
- policycoreutils-python
|
|
|
|
- setools
|
2020-06-30 18:59:53 +02:00
|
|
|
state: present
|
|
|
|
when:
|
2020-07-28 12:26:38 +02:00
|
|
|
- ansible_os_family == "RedHat"
|
|
|
|
- ansible_distribution_major_version != "8"
|
2020-06-30 18:59:53 +02:00
|
|
|
|
2020-08-19 18:39:17 +02:00
|
|
|
- name: "(Setup: SELinux) Install Required CentOS/RHEL 8 Dependencies"
|
2020-06-30 18:59:53 +02:00
|
|
|
package:
|
|
|
|
name:
|
|
|
|
- selinux-policy-targeted
|
|
|
|
- libselinux-utils
|
|
|
|
- policycoreutils
|
|
|
|
state: present
|
|
|
|
when:
|
|
|
|
- ansible_os_family == "RedHat"
|
|
|
|
- ansible_distribution_major_version == "8"
|
|
|
|
|
2020-07-28 12:26:38 +02:00
|
|
|
- name: "(Setup: SELinux) Check if SELinux is Enabled"
|
2020-06-30 18:59:53 +02:00
|
|
|
debug:
|
|
|
|
msg: "You need to enable selinux, if it was disabled you need to reboot"
|
|
|
|
when: ansible_selinux is undefined
|
|
|
|
|
2020-07-28 12:26:38 +02:00
|
|
|
- name: "(Setup: SELinux) Setup Permissive SELinux"
|
2020-06-30 18:59:53 +02:00
|
|
|
selinux:
|
|
|
|
state: permissive
|
|
|
|
policy: targeted
|
|
|
|
changed_when: false
|
|
|
|
when: ansible_selinux.mode == "enforcing"
|
|
|
|
|
2020-07-28 12:26:38 +02:00
|
|
|
- name: "(Setup: SELinux) Allow HTTP Network Connection"
|
2020-06-30 18:59:53 +02:00
|
|
|
seboolean:
|
|
|
|
name: httpd_can_network_connect
|
|
|
|
state: yes
|
|
|
|
persistent: yes
|
|
|
|
|
2020-07-28 12:26:38 +02:00
|
|
|
- name: "(Setup: SELinux) Allow HTTP Relay Connection"
|
2020-06-30 18:59:53 +02:00
|
|
|
seboolean:
|
|
|
|
name: httpd_can_network_relay
|
|
|
|
state: yes
|
|
|
|
persistent: yes
|
|
|
|
|
2020-07-28 12:26:38 +02:00
|
|
|
- name: "(Setup: SELinux) Allow Status Ports"
|
2020-06-30 18:59:53 +02:00
|
|
|
seport:
|
|
|
|
ports: "{{ nginx_status_port }}"
|
|
|
|
proto: tcp
|
|
|
|
setype: http_port_t
|
|
|
|
state: present
|
|
|
|
when: nginx_status_port is defined
|
|
|
|
|
2020-07-28 12:26:38 +02:00
|
|
|
- name: "(Setup: SELinux) Allow Rest API Ports"
|
2020-06-30 18:59:53 +02:00
|
|
|
seport:
|
|
|
|
ports: "{{ nginx_rest_api_port }}"
|
|
|
|
proto: tcp
|
|
|
|
setype: http_port_t
|
|
|
|
state: present
|
2020-07-23 21:03:26 +02:00
|
|
|
when: nginx_rest_api_port is defined
|
2020-06-30 18:59:53 +02:00
|
|
|
|
2020-07-28 12:26:38 +02:00
|
|
|
- name: "(Setup: SELinux) Allow Specific TCP Ports"
|
2020-06-30 18:59:53 +02:00
|
|
|
seport:
|
|
|
|
ports: "{{ nginx_selinux_tcp_ports }}"
|
|
|
|
proto: tcp
|
|
|
|
setype: http_port_t
|
|
|
|
state: present
|
|
|
|
when: nginx_selinux_tcp_ports is defined
|
|
|
|
|
2020-07-28 12:26:38 +02:00
|
|
|
- name: "(Setup: SELinux) Allow Specific UDP Ports"
|
2020-06-30 18:59:53 +02:00
|
|
|
seport:
|
|
|
|
ports: "{{ nginx_selinux_udp_ports }}"
|
|
|
|
proto: udp
|
|
|
|
setype: http_port_t
|
|
|
|
state: present
|
|
|
|
when: nginx_selinux_udp_ports is defined
|
|
|
|
|
2020-07-28 12:26:38 +02:00
|
|
|
- name: "(Setup: SELinux) Create NGINX Plus Module"
|
2020-06-30 18:59:53 +02:00
|
|
|
template:
|
|
|
|
src: "{{ role_path }}/templates/selinux/nginx-plus-module.te.j2"
|
|
|
|
dest: "{{ nginx_tempdir }}/nginx-plus-module.te"
|
|
|
|
register: nginx_selinux_module
|
|
|
|
|
2020-07-28 12:26:38 +02:00
|
|
|
- name: "(Setup: SELinux) Check NGINX Plus Module"
|
2020-06-30 18:59:53 +02:00
|
|
|
command: "checkmodule -M -m -o {{ nginx_tempdir }}/nginx-plus-module.mod {{ nginx_tempdir }}/nginx-plus-module.te"
|
|
|
|
args:
|
|
|
|
creates: "{{ nginx_tempdir }}/nginx-plus-module.mod"
|
|
|
|
changed_when: false
|
|
|
|
|
2020-07-28 12:26:38 +02:00
|
|
|
- name: "(Setup: SELinux) Compile NGINX Plus Module"
|
2020-06-30 18:59:53 +02:00
|
|
|
command: "semodule_package -o {{ nginx_tempdir }}/nginx-plus-module.pp -m {{ nginx_tempdir }}/nginx-plus-module.mod"
|
|
|
|
args:
|
|
|
|
creates: "{{ nginx_tempdir }}/nginx-plus-module.pp"
|
|
|
|
changed_when: false
|
|
|
|
|
2020-07-28 12:26:38 +02:00
|
|
|
- name: "(Setup: SELinux) Import NGINX Plus Module"
|
|
|
|
command: "semodule -i {{ nginx_tempdir }}/nginx-plus-module.pp" # noqa 503
|
2020-06-30 18:59:53 +02:00
|
|
|
changed_when: false
|
|
|
|
when: nginx_selinux_module.changed
|
|
|
|
|
|
|
|
- name: "(Setup: SELinux) Enforce SELinux"
|
|
|
|
selinux:
|
|
|
|
state: enforcing
|
|
|
|
policy: targeted
|
|
|
|
changed_when: false
|
2020-07-28 12:26:38 +02:00
|
|
|
when:
|
|
|
|
- nginx_selinux_enforcing
|
|
|
|
- ansible_selinux.mode == "permissive"
|