main.yml 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. ---
  2. # Deploys the infrastructure modifications needed to support SNOx node installation:
  3. #
  4. # - DNS zone files
  5. # - DNS zone configuration
  6. # - bastion zone delegation
  7. # - DHCP server modifications
  8. #
  9. # REQUIRES:
  10. # - variable "node" according to vms structure
  11. #
  12. - name: Publish forward DNS zone
  13. template:
  14. src: templates/sno.zone.j2
  15. dest: /var/named/{{ node.cluster }}.example.com.zone
  16. mode: 0640
  17. owner: root
  18. group: named
  19. notify:
  20. - reload_named
  21. - name: Configure DNS to load the published zone
  22. lineinfile:
  23. path: /etc/named.conf
  24. insertafter: "^# BEGIN ANSIBLE MANAGED DNS ZONES$"
  25. regexp: '^zone "{{ node.cluster }}.example.com"'
  26. line: 'zone "{{ node.cluster }}.example.com" { type master; file "{{ node.cluster }}.example.com.zone"; allow-update { none; }; };'
  27. state: present
  28. notify:
  29. - reload_named
  30. - name: Update reverse DNS zone
  31. lineinfile:
  32. path: /var/named/50.168.192.in-addr.arpa.zone
  33. insertafter: "^; BEGIN DYNAMIC 50 rZONE RECORDS$"
  34. regexp: "^{{ node.ip | regex_replace('^192.168.50.', '') }}"
  35. line: "{{ node.ip | regex_replace('^192.168.50.', '') }} IN PTR {{ node.name }}.{{ node.cluster }}.example.com."
  36. state: present
  37. register: zoneupdate
  38. - name: Extract the serial if rzone was updated
  39. shell: grep -i serial /var/named/50.168.192.in-addr.arpa.zone | awk '{ print $1 }'
  40. register: rzone_serial_result
  41. when: zoneupdate.changed
  42. - name: Bump up the serial if rzone was updated
  43. set_fact:
  44. rzone_serial: "{{ rzone_serial_result.stdout | int + 1 }}"
  45. when: zoneupdate.changed
  46. - name: Update the serial number of reverse DNS zone
  47. lineinfile:
  48. path: /var/named/50.168.192.in-addr.arpa.zone
  49. regexp: "(?i); serial"
  50. line: " {{ rzone_serial }} ; serial"
  51. state: present
  52. when: zoneupdate.changed
  53. notify:
  54. - reload_named
  55. - name: Delegate the new zone to utility from bastion
  56. delegate_to: bastion.lab.example.com
  57. template:
  58. src: templates/dnsmasq.conf.j2
  59. dest: /etc/dnsmasq.d/{{ node.cluster }}.conf
  60. mode: 0644
  61. owner: root
  62. group: root
  63. notify: restart_bastion_dnsmasq
  64. - name: Make sure DHCP server recognizes us
  65. lineinfile:
  66. path: /etc/dhcp/dhcpd.conf
  67. insertafter: "^# BEGIN ANSIBLE MANAGED DHCP CONFIG$"
  68. regexp: "(?i)hardware ethernet {{ node.mac | regex_replace('^01-', '') | regex_replace('-', ':') }}"
  69. line: 'host {{ node.name }}-{{ node.cluster }} { hardware ethernet {{ node.mac | regex_replace("^01-", "") | regex_replace("-", ":") }}; fixed-address {{ node.ip }}; option host-name "{{ node.name }}.{{ node.cluster }}.example.com"; option domain-name "{{ node.cluster }}.example.com"; option domain-search "{{ node.cluster }}.example.com"; }'
  70. state: present
  71. notify: restart_dhcpd
  72. ...