--- - name: "Create file: /usr/local/bin/acme-redirect-fixpermissions" copy: content: "#!/bin/sh\n/bin/chown -R acme-redirect:acme-redirect /var/lib/acme-redirect/live\n/bin/chown -R acme-redirect:acme-redirect /var/lib/acme-redirect/certs" dest: /usr/local/bin/acme-redirect-fixpermissions mode: 0755 - name: "[Alpine] create sudoers file for acme-redirect" copy: content: "acme-redirect ALL=NOPASSWD:/sbin/rc-service,/usr/local/bin/acme-redirect-fixpermissions\n" dest: /etc/sudoers.d/acme-redirect when: - ansible_distribution == "Alpine" - name: "[Archlinux] create sudoers file for acme-redirect" copy: content: "acme-redirect ALL=NOPASSWD:/usr/bin/systemctl,/usr/local/bin/acme-redirect-fixpermissions\n" dest: /etc/sudoers.d/acme-redirect when: - ansible_distribution == "Archlinux" - name: "Create file: /etc/acme-redirect.conf" template: src: acme-redirect-general.conf.j2 dest: /etc/acme-redirect.conf owner: acme-redirect group: acme-redirect notify: "Restart acme-redirect" - name: "Create directory: /etc/acme-redirect.d" file: state: "directory" path: /etc/acme-redirect.d owner: acme-redirect group: acme-redirect mode: 0755 when: - services.acme_redirect.certs is defined - name: Generate acme-redirect cert configs template: src: acme-redirect.conf.j2 dest: /etc/acme-redirect.d/{{item.key}}.conf owner: acme-redirect group: acme-redirect mode: 0644 loop: "{{ lookup('dict', services.acme_redirect.certs, wantlist=True) }}" register: acme_redirect_deployed_configs notify: "Restart acme-redirect" when: - services.acme_redirect.certs is defined - name: "Collect files in directory: /etc/acme-redirect.d" find: path: /etc/acme-redirect.d hidden: yes register: acme_redirect_found_files check_mode: no changed_when: false when: - services.acme_redirect.certs is defined - name: "Remove unmanaged files in directory: /etc/acme-redirect.d" file: path: "/etc/acme-redirect.d/{{ item.path | basename }}" state: absent with_items: - "{{ acme_redirect_found_files.files }}" notify: "Restart acme-redirect" when: - services.acme_redirect.certs is defined - (item.path) not in ( acme_redirect_deployed_configs | json_query('results[].invocation.module_args.dest') | default([]) )