Improved stability of role pve-nginx-redirector

- Automatically install nginx-light if nginx is not installed at all
- Create custom systemd unit file modifying startup preceedence of nginx
  This also fixes #1
This commit is contained in:
Jan 2019-01-06 06:23:56 +01:00
parent ff7aa5cdb4
commit bbbbce3137
2 changed files with 27 additions and 4 deletions

View File

@ -2,3 +2,7 @@
- name: Restart nginx - name: Restart nginx
service: name=nginx state=restarted service: name=nginx state=restarted
- name: Systemd reload
systemd:
daemon_reload: yes

View File

@ -1,10 +1,29 @@
--- ---
- name: Check if nginx is installed - name: Stat nginx_binary
stat: path=/etc/nginx stat: path=/usr/sbin/nginx
register: nginx register: nginx_binary
- name: Install nginx-light
apt: name=nginx-light state=present
when: nginx_binary.stat.exists == False
- name: Stat nginx local service file
stat: path=/etc/systemd/system/nginx.service
register: nginx_service
- name: Make custom nginx.service
command: cp /lib/systemd/system/nginx.service /etc/systemd/system/nginx.service
when: nginx_service.stat.exists == False
- name: Configuring nginx to start after pve populated its fuse-mounts
lineinfile:
path: /etc/systemd/system/nginx.service
regexp: '^After='
line: 'After=pve-guests.service'
insertafter: '^\[Unit\]'
notify: Systemd reload
- name: Configuring nginx pve redirector 80 -> 443 -> 8006 - name: Configuring nginx pve redirector 80 -> 443 -> 8006
template: src=redirect.j2 dest=/etc/nginx/sites-enabled/redirect mode=0644 template: src=redirect.j2 dest=/etc/nginx/sites-enabled/redirect mode=0644
notify: Restart nginx notify: Restart nginx
when: nginx.stat.exists == True