mirror of
https://github.com/spantaleev/matrix-docker-ansible-deploy.git
synced 2024-11-14 10:04:46 +08:00
Use Ansible dig lookup instead of calling the dig program
This means we no longer have a dependency on the `dig` program, but we do have a dependency on `dnspython`. Improves things as suggested in #65 (Github issue).
This commit is contained in:
parent
65d4fe7e0c
commit
f92c4d5a27
@ -1,24 +1,23 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
|
# This requires the dnspython library and will fail with a friendly error when unavailable.
|
||||||
- name: Check DNS SRV record
|
- name: Check DNS SRV record
|
||||||
shell:
|
set_fact:
|
||||||
cmd: "dig -t srv {{ ('_matrix._tcp.' + hostname_identity + '.')|quote }}"
|
result_dig_srv: "{{ lookup('dig', ('_matrix._tcp.' + hostname_identity + './SRV'), 'flat=0', wantlist=False) }}"
|
||||||
register: result_dig_srv
|
|
||||||
changed_when: false
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- name: Fail if dig failed
|
- name: Fail if DNS SRV record missing
|
||||||
fail:
|
fail:
|
||||||
msg: "Failed checking DNS SRV record. You likely don't have the `dig` program installed locally. Full error: {{ result_dig_srv }}"
|
msg: "It appears the DNS SRV record for {{ hostname_identity }} is not set up correctly (the record is missing). See the 'Configuring DNS' documentation for this playbook."
|
||||||
when: "result_dig_srv.stderr != ''"
|
when: "result_dig_srv == 'NXDOMAIN'"
|
||||||
|
|
||||||
# We expect an answer like this:
|
|
||||||
# ;; ANSWER SECTION:
|
|
||||||
# _matrix._tcp.DOMAIN. 10800 IN SRV 10 0 8448 matrix.DOMAIN.
|
|
||||||
- name: Fail if DNS SRV record incorrect
|
- name: Fail if DNS SRV record incorrect
|
||||||
fail:
|
fail:
|
||||||
msg: "It appears the DNS SRV record for {{ hostname_identity }} is not set up correctly. See the 'Configuring DNS' documentation for this playbook. Full DNS answer was: {{ result_dig_srv.stdout }}"
|
msg: >
|
||||||
when: "('8448 ' + hostname_matrix) not in result_dig_srv.stdout"
|
It appears the DNS SRV record for {{ hostname_identity }} is not set up correctly.
|
||||||
|
Expected it to point to `{{ (hostname_matrix + '.') }}` (port 8448).
|
||||||
|
Found it pointing to `{{ result_dig_srv.target }}` (port {{ result_dig_srv.port }}).
|
||||||
|
See the 'Configuring DNS' documentation for this playbook.
|
||||||
|
when: "result_dig_srv.target != (hostname_matrix + '.') or result_dig_srv.port != 8448"
|
||||||
|
|
||||||
- name: Report correct DNS SRV record
|
- name: Report correct DNS SRV record
|
||||||
debug:
|
debug:
|
||||||
|
Loading…
Reference in New Issue
Block a user