- name: List currently existing letsencrypt certificates
find:
paths={{ item.paths }}
file_type={{ item.file_type }}
register: haproxy_le_existing
with_items:
- { paths: /etc/letsencrypt/live/, file_type: directory}
- { paths: /etc/haproxy/ssl/le/, file_type: file}
- debug: var='haproxy_le_ssl|map(attribute="domain")|list|join("|")'
- debug: var='haproxy_le_existing.results|sum(attribute='files', start=[])|map(attribute='path')|map('regex_search','^((?!{{haproxy_le_ssl|map(attribute='domain')|list|join('|')}}).)*$')| select('string') | list'
- name: Remove SSLs that are not in the config
shell: "ls -la {{ item }}"
with_items: "{{ haproxy_le_existing.results|sum(attribute='files', start=[])|map(attribute='path')|map('regex_search','^((?!{{haproxy_le_ssl|map(attribute='domain')|list|join('|')}}).)*$')| select('string') | list }}"haproxy_le_ssl:
- { domain: let2.example.is}
- { domain: let3.example.is}
- { domain: let4.example.is}TASK [common/haproxy : List currently existing letsencrypt certificates] *******
ok: [haproxy-test.aws.example] => (item={u'file_type': u'directory', u'paths': u'/etc/letsencrypt/live/'})
ok: [haproxy-test.aws.example] => (item={u'file_type': u'file', u'paths': u'/etc/haproxy/ssl/le/'})
msg: All items completed
msg: All items completed
TASK [common/haproxy : debug] **************************************************
ok: [haproxy-test.aws.example] => {
"haproxy_le_ssl|map(attribute=\"domain\")|list|join(\"|\")": "let2.example.is|let3.example.is|let4.example.is"
}
TASK [common/haproxy : debug] **************************************************
ok: [haproxy-test.aws.example] => {
"haproxy_le_existing.results|sum(attribute='files', start=[])|map(attribute='path')|map('regex_search','^((?!let2.example.is|let3.example.is|let4.example.is).)*$')| select('string') | list": [
"/etc/letsencrypt/live/let1.example.is",
"/etc/haproxy/ssl/le/dupa.pem"
]
}TASK [common/haproxy : Remove SSLs that are not in the config] *****************
fatal: [haproxy-test.aws.example]: FAILED! => {"failed": true, "msg": "template error while templating string: expected token ',', got 'domain'. String: {{ haproxy_le_existing.results|sum(attribute='files', start=[])|map(attribute='path')|map('regex_search','^((?!{{haproxy_le_ssl|map(attribute='domain')|list|join('|')}}).)*$')| select('string') | list }}"}