main.yml (1948B)
1 --- 2 # Webserver role 3 4 - name: Install Nginx 5 apt: 6 policy_rc_d: 101 7 name: nginx 8 state: present 9 update_cache: true 10 when: ansible_facts["os_family"] == 'Debian' 11 12 - name: Install certbot base package 13 apt: 14 policy_rc_d: 101 15 name: certbot 16 state: present 17 update_cache: true 18 when: ansible_facts["os_family"] == 'Debian' 19 20 - name: Install certbot nginx plugin 21 apt: 22 policy_rc_d: 101 23 name: python3-certbot-nginx 24 state: present 25 update_cache: true 26 when: ansible_facts["os_family"] == 'Debian' 27 28 - name: Remove default nginx configuration 29 file: 30 path: /etc/nginx/sites-enabled/default 31 state: absent 32 notify: Restart nginx 33 34 - name: Setup extended log format 35 copy: 36 src: etc/nginx/conf.d/log-format-apm.conf 37 dest: /etc/nginx/conf.d/log-format-apm.conf 38 owner: root 39 group: root 40 mode: "0644" 41 notify: Restart nginx 42 43 - name: Configure exchange timing log request selection 44 ansible.builtin.template: 45 src: exchange-latency.conf.j2 46 dest: /etc/nginx/conf.d/exchange-latency.conf 47 owner: root 48 group: root 49 mode: "0644" 50 notify: Restart nginx 51 52 - name: Remove obsolete global HTTP2/HTTP3 configuration 53 ansible.builtin.file: 54 path: /etc/nginx/conf.d/http2-http3.conf 55 state: absent 56 notify: Restart nginx 57 58 - name: Setup per-server HTTPS configuration 59 copy: 60 src: etc/nginx/conf.d/listen.conf.inc 61 dest: /etc/nginx/conf.d/listen.conf.inc 62 owner: root 63 group: root 64 mode: "0644" 65 notify: Restart nginx 66 67 - name: Validate nginx configuration without removing enabled sites 68 ansible.builtin.command: nginx -c /etc/nginx/nginx.conf -t 69 # Files written by an interrupted deployment no longer notify on a retry. 70 changed_when: deployment_recover_configuration | default(false) | bool 71 notify: Restart nginx 72 check_mode: false 73 74 - name: Ensure Nginx service is enabled and started 75 service: 76 name: nginx 77 state: started 78 enabled: true