xoxys.nginx/tasks/install.yml

130 lines
3.4 KiB
YAML
Raw Normal View History

2017-07-15 15:45:46 +02:00
---
2017-12-23 12:30:23 +01:00
- block:
2018-10-22 10:56:39 +02:00
- name: Add nginx repository
yum_repository:
name: nginx
file: nginx
description: NGINX High Performance Web Server
baseurl: "https://nginx.org/packages/centos/{{ ansible_distribution_major_version }}/$basearch/"
gpgkey: https://nginx.org/keys/nginx_signing.key
gpgcheck: yes
when: nginx_official_repo_enabled | bool
2017-12-23 12:30:23 +01:00
2018-10-22 10:56:39 +02:00
- name: Installing nginx
2018-12-08 15:49:09 +01:00
package:
2018-10-22 10:56:39 +02:00
name: nginx
2018-12-08 15:49:09 +01:00
state: present
2017-12-23 12:30:23 +01:00
2018-10-22 10:56:39 +02:00
- name: Create group '{{ nginx_group }}'
group:
name: "{{ nginx_group }}"
state: present
when: nginx_group != "nginx"
2017-12-24 14:05:27 +01:00
2018-10-22 10:56:39 +02:00
- name: Create user '{{ nginx_user }}'
user:
name: "{{ nginx_user }}"
group: "{{ nginx_group }}"
createhome: no
shell: /sbin/nologin
when: nginx_user != "nginx"
2017-12-24 14:05:27 +01:00
2018-10-22 10:56:39 +02:00
- name: Prepare vhost directories
file:
path: "{{ item }}"
state: directory
owner: "{{ nginx_user }}"
group: "{{ nginx_group }}"
mode: 0750
loop:
2018-10-22 10:56:39 +02:00
- "{{ nginx_vhosts_dir }}"
- "{{ nginx_vhosts_dir }}/default"
2017-12-23 12:30:23 +01:00
2018-10-22 10:56:39 +02:00
- name: Prepare nginx directories
file:
path: "{{ item }}"
state: directory
owner: root
group: root
mode: 0640
loop:
2018-10-22 10:56:39 +02:00
- /etc/nginx/sites-available
- /etc/nginx/sites-enabled
2017-12-23 12:30:23 +01:00
2018-10-22 10:56:39 +02:00
- name: Update nginx.conf
template:
src: etc/nginx/nginx.conf.j2
dest: "/etc/nginx/nginx.conf"
owner: root
group: root
mode: 0640
notify: __nginx_reload
2017-12-23 12:30:23 +01:00
2018-10-22 10:56:39 +02:00
- name: Remove default.conf from conf.d
2021-05-25 18:33:08 +02:00
copy:
content: |
# Ansible managed.
# File not in use.
dest: /etc/nginx/conf.d/default.conf
2021-05-25 18:39:38 +02:00
mode: 0640
2017-12-23 12:30:23 +01:00
2018-10-22 10:56:39 +02:00
- name: Update header.conf
template:
src: etc/nginx/conf.d/header.conf.j2
dest: /etc/nginx/conf.d/header.conf
owner: root
group: root
mode: 0640
notify: __nginx_reload
2017-12-23 12:30:23 +01:00
- name: Add custom error page template
template:
src: usr/share/nginx/html/error.html.j2
2020-05-25 11:14:57 +02:00
dest: /usr/share/nginx/html/error.html
owner: root
group: root
mode: 0644
notify: __nginx_reload
2018-10-22 10:56:39 +02:00
- name: Set selinux booleans
seboolean:
2019-07-17 23:47:31 +02:00
name: "{{ item.name }}"
2018-10-22 10:56:39 +02:00
state: "{{ item.state }}"
persistent: "{{ item.persistent }}"
loop: "{{ nginx_set_sebooleans }}"
2018-10-22 10:56:39 +02:00
when: nginx_set_sebooleans is defined
2019-02-20 22:54:30 +01:00
2020-02-23 17:10:49 +01:00
- name: Allow to bind to custom ports
seport:
ports: "{{ item.port }}"
2020-02-23 17:13:41 +01:00
proto: "{{ item.proto | default('tcp') }}"
2020-02-23 17:10:49 +01:00
setype: http_port_t
state: "{{ item.state | default('present') }}"
loop: "{{ nginx_set_seports }}"
loop_control:
label: "{{ item.port }}"
when: nginx_set_seports is defined
2019-02-20 22:54:30 +01:00
- name: Fix selinux file context mappaing for pid file
sefcontext:
target: '/var/run/nginx(/.*)?'
setype: httpd_var_run_t
state: present
- name: Apply new SELinux file context to filesystem
command: restorecon -irv /var/run
2019-02-21 21:50:45 +01:00
changed_when: False
2017-12-23 12:30:23 +01:00
become: True
become_user: root
2017-12-22 21:31:20 +01:00
2018-08-12 11:31:12 +02:00
- block:
2019-07-17 23:56:25 +02:00
- name: Add default page
template:
src: var/www/vhosts/default/index.html.j2
dest: /var/www/vhosts/default/index.html
owner: "{{ nginx_user }}"
group: "{{ nginx_group }}"
mode: 0750
become: True
become_user: "{{ nginx_user }}"