diff --git a/handlers/main.yml b/handlers/main.yml index cafbeb477cd41ff9830faabc7b653dbc967ec7ca..236af4cd249d376e06112552b720fca5e152424d 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,4 +1,4 @@ --- # file: roles/letsencrypt/handler/main.yml -- include: '../../haproxy/handlers/main.yml' +- import_tasks: '../../haproxy/handlers/main.yml' diff --git a/tasks/cert.yml b/tasks/cert.yml index 7d2a1a6095c0e59754ac4427147975fcbf341e88..bc93e788aba02d8df8191966fcaea17ebbd25bfb 100644 --- a/tasks/cert.yml +++ b/tasks/cert.yml @@ -1,53 +1,21 @@ --- # file: roles/letsencrypt/tasks/cert.yml -- set_fact: cert={{ domain.1|default(domain) }} -- set_fact: port={{ ('proxyserver' in groups)|ternary(54321,80) }} - -- name: "Write Config" - template: - src: 'letsencrypt.ini' - dest: '/etc/letsencrypt/{{ cert.domain }}.ini' - owner: 'root' - group: 'root' - mode: '644' - register: cert_definition - - block: - - name: "Stop services" - service: - name: '{{ item }}' - state: 'stopped' - with_items: '{{ letsencrypt_pause_services|default([]) }}' - - - name: "Open Port" - iptables: - chain: 'INPUT' - source: '0.0.0.0' - destination_port: 54321 - protocol: 'tcp' - jump: 'ACCEPT' - state: 'present' - - - name: "Install New Cert" - shell: certbot certonly --expand --non-interactive --config /etc/letsencrypt/{{ cert.domain }}.ini --http-01-port {{ port }} --preferred-challenges http-01 - ignore_errors: true + - set_fact: cert={{ domain.1|default(domain) }} + - set_fact: port={{ ('proxyserver' in groups)|ternary(54321,80) }} - - name: "Close Port" - iptables: - chain: 'INPUT' - source: '0.0.0.0' - destination_port: 54321 - protocol: 'tcp' - jump: 'ACCEPT' - state: 'absent' + - name: "Write Config" + template: + src: 'letsencrypt.ini' + dest: '/etc/letsencrypt/{{ cert.domain }}.ini' + owner: 'root' + group: 'root' + mode: '644' + register: cert_definition - - name: "Start services" - service: - name: '{{ item }}' - state: 'started' - with_items: '{{ letsencrypt_pause_services|default([]) }}' - ignore_errors: true + - import_tasks: cert_generate.yml + when: cert_definition.changed - when: cert_definition.changed + tags: 'ApacheConfig' diff --git a/tasks/cert_generate.yml b/tasks/cert_generate.yml new file mode 100644 index 0000000000000000000000000000000000000000..8710151372598b555e9c0a66c8254503e6a10d90 --- /dev/null +++ b/tasks/cert_generate.yml @@ -0,0 +1,37 @@ +--- +# file: roles/letsencrypt/tasks/cert_generate.yml + +- name: "Stop services" + service: + name: '{{ item }}' + state: 'stopped' + with_items: '{{ letsencrypt_pause_services|default([]) }}' + +- name: "Open Port" + iptables: + chain: 'INPUT' + source: '0.0.0.0' + destination_port: 54321 + protocol: 'tcp' + jump: 'ACCEPT' + state: 'present' + +- name: "Install New Cert" + shell: certbot certonly --expand --non-interactive --config /etc/letsencrypt/{{ cert.domain }}.ini --http-01-port {{ port }} --preferred-challenges http-01 + ignore_errors: true + +- name: "Close Port" + iptables: + chain: 'INPUT' + source: '0.0.0.0' + destination_port: 54321 + protocol: 'tcp' + jump: 'ACCEPT' + state: 'absent' + +- name: "Start services" + service: + name: '{{ item }}' + state: 'started' + with_items: '{{ letsencrypt_pause_services|default([]) }}' + ignore_errors: true diff --git a/tasks/main.yml b/tasks/main.yml index 8a0d38e1276df3f193ff6c9af153de4b2ba6817e..fe2e6252315135a85d2ad8252680e3054b293c96 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -20,18 +20,18 @@ changed_when: false tags: 'always' - - include: install.yml + - import_tasks: install.yml - - include: cert.yml + - include_tasks: cert.yml with_items: '{{ letsencrypt_certificates|default([]) }}' loop_control: loop_var: domain - - include: renew.yml + - import_tasks: renew.yml when: letsencrypt_certs_available is defined and letsencrypt_certs_available.stat.exists and (proxy_active is not defined or proxy_active) tags: 'renew' - - include_tasks: '../../haproxy/tasks/proxypool.yml' + - import_tasks: '../../haproxy/tasks/proxypool.yml' tags: 'renew' when: '"letsencrypt" not in excluded_roles' diff --git a/tasks/renew.yml b/tasks/renew.yml index fac4aef8237d9f918c55ff8e64352491cf5a981c..14368607286c1f8e5fcdc1a2c1bc336b02d4048f 100644 --- a/tasks/renew.yml +++ b/tasks/renew.yml @@ -34,7 +34,7 @@ state: 'absent' - name: "Build HaProxy Certs" - include_tasks: '../../haproxy/tasks/buildcerts.yml' + import_tasks: '../../haproxy/tasks/buildcerts.yml' tags: 'always' - name: "Start services"