main.yml (2378B)
1 --- 2 - name: Install nginx and certbot 3 apt: 4 name: 5 - nginx 6 - certbot 7 - python3-certbot-nginx 8 state: present 9 update_cache: true 10 11 - name: Remove default nginx site 12 file: 13 path: /etc/nginx/sites-enabled/default 14 state: absent 15 notify: reload nginx 16 17 - name: Create blog webroot 18 file: 19 path: /var/www/learningunix.net/html 20 state: directory 21 owner: cjr 22 group: www-data 23 mode: '0755' 24 25 - name: Check if cert exists 26 stat: 27 path: /etc/letsencrypt/live/learningunix.net/fullchain.pem 28 register: cert 29 30 - name: Deploy HTTP-only learningunix.net vhost 31 copy: 32 src: learningunix.net.conf 33 dest: /etc/nginx/sites-available/learningunix.net.conf 34 when: not cert.stat.exists 35 notify: reload nginx 36 37 - name: Deploy HTTP-only gitea vhost 38 copy: 39 src: gitea.conf 40 dest: /etc/nginx/sites-available/gitea.conf 41 when: not cert.stat.exists 42 notify: reload nginx 43 44 - name: Enable learningunix.net site 45 file: 46 src: /etc/nginx/sites-available/learningunix.net.conf 47 dest: /etc/nginx/sites-enabled/learningunix.net.conf 48 state: link 49 notify: reload nginx 50 51 - name: Enable gitea site 52 file: 53 src: /etc/nginx/sites-available/gitea.conf 54 dest: /etc/nginx/sites-enabled/gitea.conf 55 state: link 56 notify: reload nginx 57 58 - name: Start and enable nginx 59 service: 60 name: nginx 61 state: started 62 enabled: true 63 64 - name: Flush handlers to reload nginx before certbot runs 65 meta: flush_handlers 66 67 - name: Obtain SSL certificates 68 command: > 69 certbot --nginx 70 -d learningunix.net 71 -d gitea.learningunix.net 72 --non-interactive 73 --agree-tos 74 --email chris.roberts@learningunix.net 75 --redirect 76 args: 77 creates: /etc/letsencrypt/live/learningunix.net/fullchain.pem 78 79 - name: Deploy SSL learningunix.net vhost 80 copy: 81 src: learningunix.net-ssl.conf 82 dest: /etc/nginx/sites-available/learningunix.net.conf 83 notify: reload nginx 84 85 - name: Deploy SSL gitea vhost 86 copy: 87 src: gitea-ssl.conf 88 dest: /etc/nginx/sites-available/gitea.conf 89 notify: reload nginx 90 91 - name: Deploy default server block 92 copy: 93 src: default.conf 94 dest: /etc/nginx/sites-available/default.conf 95 notify: reload nginx 96 97 - name: Enable default server block 98 file: 99 src: /etc/nginx/sites-available/default.conf 100 dest: /etc/nginx/sites-enabled/default.conf 101 state: link 102 notify: reload nginx