- name: Install certbot
  apt:
    name:
      - certbot
    state: present

- name: Register certbot
  shell: |
    certbot -n register --agree-tos --email ngyimesi@sch.bme.hu
    touch /etc/letsencrypt/.registered
  args:
    creates: /etc/letsencrypt/.registered
  tags:
    - nginx
    - certbot

- name: Setup cronjob for renewal
  cron:
    name: certbot-renewal
    job: "certbot -q renew'"
    minute: "0"
    hour: "14"
  tags:
    - nginx
    - certbot

- name: 'Get certificate'
  command: 'certbot -n --nginx certonly -d {{ full_hostname }}'
  args:
    creates: '/etc/letsencrypt/live/{{ full_hostname }}'
  ignore_errors: true
  tags:
    - nginx
    - certbot