diff --git a/defaults/main.yml b/defaults/main.yml index dc1034e2..62fe9c1f 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -5,11 +5,11 @@ certbot_auto_renew_user: "{{ ansible_user | default(lookup('env', 'USER')) }}" certbot_auto_renew_hour: "3" certbot_auto_renew_minute: "30" certbot_auto_renew_options: "--quiet" +certbot_package: certbot certbot_testmode: false certbot_hsts: false - # Parameters used when creating new Certbot certs. certbot_create_if_missing: false certbot_create_method: standalone diff --git a/tasks/create-cert-nginx.yml b/tasks/create-cert-nginx.yml new file mode 100644 index 00000000..7038b8d3 --- /dev/null +++ b/tasks/create-cert-nginx.yml @@ -0,0 +1,9 @@ +--- +- name: Check if certificate already exists. + stat: + path: /etc/letsencrypt/live/{{ cert_item.domains | first }}/cert.pem + register: letsencrypt_cert + +- name: Generate new certificate if one doesn't exist. + command: "{{ certbot_create_command }}" + when: not letsencrypt_cert.stat.exists diff --git a/tasks/include-vars.yml b/tasks/include-vars.yml deleted file mode 100644 index 0a70e503..00000000 --- a/tasks/include-vars.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -- name: Load a variable file based on the OS type, or a default if not found. - include_vars: "{{ item }}" - with_first_found: - - "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yml" - - "{{ ansible_distribution }}.yml" - - "{{ ansible_os_family }}.yml" - - "default.yml" diff --git a/tasks/install-with-package.yml b/tasks/install-with-package.yml index 10490ffd..543610b2 100644 --- a/tasks/install-with-package.yml +++ b/tasks/install-with-package.yml @@ -4,4 +4,4 @@ - name: Set Certbot script variable. set_fact: - certbot_script: "{{ certbot_package }}" + certbot_script: "certbot" diff --git a/tasks/main.yml b/tasks/main.yml index 894143c7..200bdc7d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,6 +1,4 @@ --- -- import_tasks: include-vars.yml - - import_tasks: setup-RedHat.yml when: ansible_os_family == 'RedHat' @@ -29,5 +27,13 @@ loop_control: loop_var: cert_item +- include_tasks: create-cert-nginx.yml + with_items: "{{ certbot_certs }}" + when: + - certbot_create_if_missing + - certbot_create_method == 'nginx' + loop_control: + loop_var: cert_item + - import_tasks: renew-cron.yml when: certbot_auto_renew diff --git a/vars/Ubuntu-16.04.yml b/vars/Ubuntu-16.04.yml deleted file mode 100644 index 83cf124a..00000000 --- a/vars/Ubuntu-16.04.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -certbot_package: letsencrypt diff --git a/vars/default.yml b/vars/default.yml deleted file mode 100644 index d88f2dc5..00000000 --- a/vars/default.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -certbot_package: certbot