Matrix Docker Ansible eploy
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 

69 rindas
3.9 KiB

  1. ---
  2. # This requires the dnspython library which is usually unavailable.
  3. - name: Check DNS SRV record for {{ dns_srv_record_check.service_and_protocol }} on {{ dns_srv_record_check.domain }} using Ansible dig lookup
  4. set_fact:
  5. lookup_dig_srv: "{{ lookup('dig', (dns_srv_record_check.service_and_protocol + '.' + dns_srv_record_check.domain + '/SRV'), 'flat=0', wantlist=False) }}"
  6. register: result_lookup_dig_srv
  7. ignore_errors: true
  8. - name: Fail if DNS SRV check via Ansible dig lookup failed for non-dependency reason
  9. fail:
  10. msg: "DNS SRV record check via Ansible dig lookup plugin (which uses the dnspython package) failed. Error is: {{ result_lookup_dig_srv.msg }}"
  11. when: "result_lookup_dig_srv.failed and 'dnspython' not in result_lookup_dig_srv.msg"
  12. # Fallback to using the dig CLI tool if dnspython was unavailable.
  13. - name: Check DNS SRV record for {{ dns_srv_record_check.service_and_protocol }} on {{ dns_srv_record_check.domain }} using dig CLI tool
  14. shell:
  15. cmd: "dig -t srv {{ (dns_srv_record_check.service_and_protocol + '.' + dns_srv_record_check.domain)|quote }}"
  16. register: result_cli_dig_srv
  17. changed_when: false
  18. ignore_errors: true
  19. when: "lookup_dig_srv is not defined"
  20. - name: Fail if dig CLI used and failed
  21. fail:
  22. msg: >-
  23. Failed performing DNS SRV record check.
  24. You neither have the `dnspython` Python package, nor the `dig` program installed locally.
  25. You need to install one of those, so we could perform a DNS SRV record check.
  26. Full error from trying to run `dig`: {{ result_cli_dig_srv }}
  27. when: "lookup_dig_srv is not defined and result_cli_dig_srv.stderr != ''"
  28. # Some DNS servers may respond with '' (stands for "No Answer").
  29. # Most usually, a missing record would yield a 'NXDOMAIN' response.
  30. # In any case, we consider any non-mapping response to mean "missing record".
  31. - name: Fail if DNS SRV record missing (Ansible dig lookup)
  32. fail:
  33. msg: >-
  34. It appears the DNS SRV record for {{ dns_srv_record_check.service_and_protocol }} on {{ dns_srv_record_check.domain }} is not set up correctly (the record is missing).
  35. See the 'Configuring DNS' documentation for this playbook.
  36. when: "lookup_dig_srv is defined and lookup_dig_srv is not mapping"
  37. - name: Fail if DNS SRV record incorrect (Ansible dig lookup)
  38. fail:
  39. msg: >-
  40. It appears the DNS SRV record for {{ dns_srv_record_check.service_and_protocol }} on {{ dns_srv_record_check.domain }} is not set up correctly.
  41. Expected it to point to `{{ dns_srv_record_check.expected_target }}` (port {{ dns_srv_record_check.expected_port }}).
  42. Found it pointing to `{{ lookup_dig_srv.target }}` (port {{ lookup_dig_srv.port }}).
  43. See the 'Configuring DNS' documentation for this playbook.
  44. when: "lookup_dig_srv is defined and (lookup_dig_srv.target != dns_srv_record_check.expected_target or lookup_dig_srv.port != dns_srv_record_check.expected_port)"
  45. # We expect an answer like this:
  46. # ;; ANSWER SECTION:
  47. # _matrix._tcp.DOMAIN. 10800 IN SRV 10 0 8448 matrix.DOMAIN.
  48. - name: Fail if DNS SRV record missing or incorrect (dig CLI tool)
  49. fail:
  50. msg: >-
  51. It appears the DNS SRV record for {{ dns_srv_record_check.service_and_protocol }} on {{ dns_srv_record_check.domain }} is not set up correctly.
  52. Expected it to point to `{{ dns_srv_record_check.expected_target }}` (port {{ dns_srv_record_check.expected_port }}).
  53. See the 'Configuring DNS' documentation for this playbook.
  54. Full response from the `dig` lookup was: {{ result_cli_dig_srv }}
  55. when: "lookup_dig_srv is not defined and (dns_srv_record_check.expected_port|string + ' ' + dns_srv_record_check.expected_target) not in result_cli_dig_srv.stdout"
  56. - name: Report correct DNS SRV record
  57. debug:
  58. msg: >-
  59. The DNS SRV record for `{{ dns_srv_record_check.service_and_protocol }}` on `{{ dns_srv_record_check.domain }}`
  60. points to `{{ dns_srv_record_check.expected_target }}` (port {{ dns_srv_record_check.expected_port }}), as expected.