populate-dns.yml 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. # TODO: use nsupdate to populate the DNS servers using the keys
  2. # specified in the inventory.
  3. # this is an optional step -- the deployers may do whatever else they
  4. # wish here.
  5. # TODO: build records
  6. # TODO: run nsupdate
  7. - name: "Generate list of private A records"
  8. set_fact:
  9. private_records: "{{ [ { 'type': 'A', 'hostname': hostvars[item]['ansible_hostname'], 'ip': hostvars[item]['private_v4'] } ] }}"
  10. with_items: "{{ groups['cluster_hosts'] }}"
  11. # - name: "Add wildcard records to the private A records for infrahosts"
  12. # set_fact:
  13. # private_records: "{{ private_records | default([]) + [ { 'type': 'A', 'hostname': '*.' + openshift_app_domain, 'ip': hostvars[item]['private_v4'] } ] }}"
  14. # with_items: "{{ groups['infra_hosts'] }}"
  15. # - name: "Add public master cluster hostname records to the private A records (single master)"
  16. # set_fact:
  17. # private_records: "{{ private_records | default([]) + [ { 'type': 'A', 'hostname': (hostvars[groups.masters[0]].openshift_master_cluster_public_hostname | replace(full_dns_domain, ''))[:-1], 'ip': hostvars[groups.masters[0]].private_v4 } ] }}"
  18. # when:
  19. # - hostvars[groups.masters[0]].openshift_master_cluster_public_hostname is defined
  20. # - openstack_num_masters == 1
  21. # - name: "Add public master cluster hostname records to the private A records (multi-master)"
  22. # set_fact:
  23. # private_records: "{{ private_records | default([]) + [ { 'type': 'A', 'hostname': (hostvars[groups.masters[0]].openshift_master_cluster_public_hostname | replace(full_dns_domain, ''))[:-1], 'ip': hostvars[groups.lb[0]].private_v4 } ] }}"
  24. # when:
  25. # - hostvars[groups.masters[0]].openshift_master_cluster_public_hostname is defined
  26. # - openstack_num_masters > 1
  27. - name: "Set the private DNS server to use the external value (if provided)"
  28. set_fact:
  29. nsupdate_server_private: "{{ external_nsupdate_keys['private']['server'] }}"
  30. nsupdate_key_secret_private: "{{ external_nsupdate_keys['private']['key_secret'] }}"
  31. nsupdate_key_algorithm_private: "{{ external_nsupdate_keys['private']['key_algorithm'] }}"
  32. nsupdate_private_key_name: "{{ external_nsupdate_keys['private']['key_name']|default('private-' + full_dns_domain) }}"
  33. when:
  34. - external_nsupdate_keys is defined
  35. - external_nsupdate_keys['private'] is defined
  36. - name: "Generate the private Add section for DNS"
  37. set_fact:
  38. private_named_records:
  39. - view: "private"
  40. zone: "{{ full_dns_domain }}"
  41. server: "{{ nsupdate_server_private }}"
  42. key_name: "{{ nsupdate_private_key_name|default('private-' + full_dns_domain) }}"
  43. key_secret: "{{ nsupdate_key_secret_private }}"
  44. key_algorithm: "{{ nsupdate_key_algorithm_private | lower }}"
  45. entries: "{{ private_records }}"
  46. # - name: "Generate list of public A records"
  47. # set_fact:
  48. # public_records: "{{ public_records | default([]) + [ { 'type': 'A', 'hostname': hostvars[item]['ansible_hostname'], 'ip': hostvars[item]['public_v4'] } ] }}"
  49. # with_items: "{{ groups['cluster_hosts'] }}"
  50. # when: hostvars[item]['public_v4'] is defined
  51. # - name: "Add wildcard records to the public A records"
  52. # set_fact:
  53. # public_records: "{{ public_records | default([]) + [ { 'type': 'A', 'hostname': '*.' + openshift_app_domain, 'ip': hostvars[item]['public_v4'] } ] }}"
  54. # with_items: "{{ groups['infra_hosts'] }}"
  55. # when: hostvars[item]['public_v4'] is defined
  56. # - name: "Add public master cluster hostname records to the public A records (single master)"
  57. # set_fact:
  58. # public_records: "{{ public_records | default([]) + [ { 'type': 'A', 'hostname': (hostvars[groups.masters[0]].openshift_master_cluster_public_hostname | replace(full_dns_domain, ''))[:-1], 'ip': hostvars[groups.masters[0]].public_v4 } ] }}"
  59. # when:
  60. # - hostvars[groups.masters[0]].openshift_master_cluster_public_hostname is defined
  61. # - openstack_num_masters == 1
  62. # - not use_bastion|bool
  63. # - name: "Add public master cluster hostname records to the public A records (single master behind a bastion)"
  64. # set_fact:
  65. # public_records: "{{ public_records | default([]) + [ { 'type': 'A', 'hostname': (hostvars[groups.masters[0]].openshift_master_cluster_public_hostname | replace(full_dns_domain, ''))[:-1], 'ip': hostvars[groups.bastions[0]].public_v4 } ] }}"
  66. # when:
  67. # - hostvars[groups.masters[0]].openshift_master_cluster_public_hostname is defined
  68. # - openstack_num_masters == 1
  69. # - use_bastion|bool
  70. # - name: "Add public master cluster hostname records to the public A records (multi-master)"
  71. # set_fact:
  72. # public_records: "{{ public_records | default([]) + [ { 'type': 'A', 'hostname': (hostvars[groups.masters[0]].openshift_master_cluster_public_hostname | replace(full_dns_domain, ''))[:-1], 'ip': hostvars[groups.lb[0]].public_v4 } ] }}"
  73. # when:
  74. # - hostvars[groups.masters[0]].openshift_master_cluster_public_hostname is defined
  75. # - openstack_num_masters > 1
  76. # - name: "Set the public DNS server details to use the external value (if provided)"
  77. # set_fact:
  78. # nsupdate_server_public: "{{ external_nsupdate_keys['public']['server'] }}"
  79. # nsupdate_key_secret_public: "{{ external_nsupdate_keys['public']['key_secret'] }}"
  80. # nsupdate_key_algorithm_public: "{{ external_nsupdate_keys['public']['key_algorithm'] }}"
  81. # nsupdate_public_key_name: "{{ external_nsupdate_keys['public']['key_name']|default('public-' + full_dns_domain) }}"
  82. # when:
  83. # - external_nsupdate_keys is defined
  84. # - external_nsupdate_keys['public'] is defined
  85. # - name: "Set the public DNS server details to use the provisioned value"
  86. # set_fact:
  87. # nsupdate_server_public: "{{ hostvars[groups['dns'][0]].public_v4 }}"
  88. # nsupdate_key_secret_public: "{{ hostvars[groups['dns'][0]].nsupdate_keys['public-' + full_dns_domain].key_secret }}"
  89. # nsupdate_key_algorithm_public: "{{ hostvars[groups['dns'][0]].nsupdate_keys['public-' + full_dns_domain].key_algorithm }}"
  90. # when:
  91. # - nsupdate_server_public is undefined
  92. # - name: "Generate the public Add section for DNS"
  93. # set_fact:
  94. # public_named_records:
  95. # - view: "public"
  96. # zone: "{{ full_dns_domain }}"
  97. # server: "{{ nsupdate_server_public }}"
  98. # key_name: "{{ nsupdate_public_key_name|default('public-' + full_dns_domain) }}"
  99. # key_secret: "{{ nsupdate_key_secret_public }}"
  100. # key_algorithm: "{{ nsupdate_key_algorithm_public | lower }}"
  101. # entries: "{{ public_records }}"
  102. - name: "Generate the final dns_records_add"
  103. set_fact:
  104. # TODO(shadower): enable this when we add public records
  105. #dns_records_add: "{{ private_named_records + public_named_records }}"
  106. dns_records_add: "{{ private_named_records }}"
  107. # RUN NSUPDATE
  108. - name: "Remove any deleted DNS A records"
  109. nsupdate:
  110. key_name: "{{ item.0.key_name }}"
  111. key_secret: "{{ item.0.key_secret }}"
  112. key_algorithm: "{{ item.0.key_algorithm }}"
  113. server: "{{ item.0.server }}"
  114. zone: "{{ item.0.zone }}"
  115. record: "{{ item.1.hostname }}"
  116. type: "{{ item.1.type }}"
  117. state: absent
  118. with_subelements:
  119. - "{{ dns_records_rm | default({}) }}"
  120. - entries
  121. register: nsupdate_remove_result
  122. until: nsupdate_remove_result|succeeded
  123. retries: 10
  124. delay: 1
  125. - name: "Add DNS A records"
  126. nsupdate:
  127. key_name: "{{ item.0.key_name }}"
  128. key_secret: "{{ item.0.key_secret }}"
  129. key_algorithm: "{{ item.0.key_algorithm }}"
  130. server: "{{ item.0.server }}"
  131. zone: "{{ item.0.zone }}"
  132. record: "{{ item.1.hostname }}"
  133. value: "{{ item.1.ip }}"
  134. type: "{{ item.1.type }}"
  135. state: present
  136. with_subelements:
  137. - "{{ dns_records_add | default({}) }}"
  138. - entries
  139. register: nsupdate_add_result
  140. until: nsupdate_add_result|succeeded
  141. retries: 10
  142. delay: 1