system-config/playbooks/roles/letsencrypt-install-txt-record/tasks/main.yaml
James E. Blair 2c03fb1e98 Handle offline hosts in LE role
If a host is offline, Ansible will not have set the required txt
keys host variable for that host.  When the task to update the
dns master with new txt records runs, it will fail due to an
undefined variable:

  'ansible.vars.hostvars.HostVarsVars object' has no attribute 'acme_txt_required'

This supplies a default value so that in that case, the task may
proceed and other hosts will have their LE certs serviced.

Change-Id: I62efbe086d801d803b2f2c3223ece8f608c668a1
2020-01-08 10:21:53 -08:00

36 lines
1019 B
YAML

- name: Make key list
set_fact:
acme_txt_keys: []
- name: Build key list
set_fact:
acme_txt_keys: '{{ acme_txt_keys }} + {{ hostvars[item]["acme_txt_required"] | default([]) }}'
with_inventory_hostnames:
- letsencrypt:!disabled
- name: Final list
debug:
var: acme_txt_keys
# NOTE(ianw): Most of the time, we won't have anything to actually do
# as we don't have new keys or renewals due.
- name: Deploy TXT records
block:
- name: Deploy new zone.db
template:
src: zone.db.j2
dest: /var/lib/bind/zones/acme.opendev.org/zone.db
- name: debug new file
slurp:
src: '/var/lib/bind/zones/acme.opendev.org/zone.db'
register: bind_zone_result
- debug:
msg: "{{ bind_zone_result['content'] | b64decode }}"
- name: Ensure domain is valid
shell: named-checkzone acme.opendev.org /var/lib/bind/zones/acme.opendev.org/zone.db
- name: Reload domain
shell: rndc reload acme.opendev.org
when: acme_txt_keys | length > 0