---
- name: Install snapd
  become: yes
  apt:
    pkg: ['snapd']
  
- name: Install snap core
  become: yes
  snap:
    name: core

- name: Install cerbot via snap
  become: yes
  snap:
    name: certbot
    classic: yes

- name: Generate certificate if needed
  become: yes
  command: /snap/bin/certbot --nginx --non-interactive --agree-tos --expand
      --domains {{ fpm_services | items2dict(key_name='server_name', value_name='server_name') | join(',') }}
        {{ reverse_services | items2dict(key_name='server_name', value_name='server_name') | join(',') }}
      --email {{certbot_email}}
