---
- name: Package - Install DNS Plugin - {{ certbot_dns_plugin }}.
  ansible.builtin.package:
    name: python{{ ansible_python.version.major }}-certbot-dns-{{ certbot_dns_plugin }}
    state: present
  when: certbot_install_method == 'package'

- name: Snap - Make sure certbot Trust Plugins With Root is set.
  ansible.builtin.command: snap set certbot trust-plugin-with-root=ok
  register: snap_set_plugin_trust_root
  changed_when: snap_set_plugin_trust_root is failed
  when: certbot_install_method == 'snap'

- name: Snap - Install DNS Plugin - {{ certbot_dns_plugin }}.
  community.general.snap:
    name: certbot-dns-{{ certbot_dns_plugin }}
  when: certbot_install_method == 'snap'

- name: Source - Check if certbot-dns-{{ certbot_dns_plugin }} plugin is installed.
  ansible.builtin.command: certbot plugins | grep dns-{{ certbot_dns_plugin }}
  register: cf_check
  ignore_errors: true
  changed_when: cf_check is failed
  when: certbot_install_method == 'source'

- name: Source - Install certbot-dns-{{ certbot_dns_plugin }}.
  ansible.builtin.command: cd {{ certbot_dir }}/certbot-dns-{{ certbot_dns_plugin }} && python setup.py install
  when: cf_check is failed
