--- - name: Add an apt key by id from a keyserver become: true ansible.builtin.apt_key: url: https://nginx.org/keys/nginx_signing.key state: present - name: Add Nginx repository into sources list become: true ansible.builtin.apt_repository: repo: deb https://nginx.org/packages/debian/ {{ ansible_facts['lsb']['codename'] }} nginx state: present - name: Add Nginx source repository into sources list become: true ansible.builtin.apt_repository: repo: deb-src https://nginx.org/packages/debian/ {{ ansible_facts['lsb']['codename'] }} nginx state: present - name: Install Nginx become: true ansible.builtin.apt: name: nginx # Creates the "nginx" user as well state: present - name: Remove default configuration become: true ansible.builtin.file: path: /etc/nginx/conf.d/default.conf state: absent notify: Restart Nginx # ---------- CERTBOT INSTALLATION ---------- # # See the installation instructions here: https://certbot.eff.org/instructions?ws=nginx&os=debianbuster&tab=wildcard - name: Install Certbot become: true community.general.snap: name: certbot classic: true state: present notify: Confirm Certbot plugin containment level - name: Flush handlers # Makes sure that the handler runs ansible.builtin.meta: flush_handlers - name: Install Certbot DNS Cloudflare plugin become: true community.general.snap: name: certbot-dns-cloudflare classic: true state: present - name: Set cloudflare variable ansible.builtin.set_fact: cloudflare_credential_dir_path: "/root/.secrets/certbot" cloudflare_credential_filename: cloudflare.ini - name: Create Certbot credential directory become: true ansible.builtin.file: path: "{{ cloudflare_credential_dir_path }}" state: directory mode: '0700' - name: Place cloudflare credential in certbot user's file become: true ansible.builtin.template: src: cloudflare.ini.j2 dest: "{{ cloudflare_credential_dir_path }}/{{ cloudflare_credential_filename }}" mode: '0400' - name: Install the certificate script become: true ansible.builtin.template: src: register_certbot_domain.sh.j2 dest: /usr/local/bin/register_certbot_domain.sh mode: '0500' - name: Create the root certificate for my domain become: true ansible.builtin.command: cmd: register_certbot_domain.sh kleinendorst.info creates: /etc/letsencrypt/live/kleinendorst.info # The certificate directory # END ------ CERTBOT INSTALLATION ------ END # - name: Start Nginx become: true ansible.builtin.systemd: name: nginx.service state: started