main.yml (1555B)
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: Remove obsolete global HTTP2/HTTP3 configuration 44 ansible.builtin.file: 45 path: /etc/nginx/conf.d/http2-http3.conf 46 state: absent 47 notify: Restart nginx 48 49 - name: Setup per-server HTTPS configuration 50 copy: 51 src: etc/nginx/conf.d/listen.conf.inc 52 dest: /etc/nginx/conf.d/listen.conf.inc 53 owner: root 54 group: root 55 mode: "0644" 56 notify: Restart nginx 57 58 - name: Validate nginx configuration without removing enabled sites 59 ansible.builtin.command: nginx -c /etc/nginx/nginx.conf -t 60 changed_when: false 61 check_mode: false 62 63 - name: Ensure Nginx service is enabled and started 64 service: 65 name: nginx 66 state: started 67 enabled: true