You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.0 KiB

  1. ---
  2. - name: set dns server for docker
  3. set_fact:
  4. docker_dns_servers: |-
  5. {%- if dns_mode == 'kubedns' -%}
  6. {{ [ skydns_server ] }}
  7. {%- elif dns_mode == 'dnsmasq_kubedns' -%}
  8. {{ [ dns_server ] }}
  9. {%- endif -%}
  10. - name: set base docker dns facts
  11. set_fact:
  12. docker_dns_search_domains:
  13. - 'default.svc.{{ dns_domain }}'
  14. - 'svc.{{ dns_domain }}'
  15. docker_dns_options:
  16. - ndots:{{ ndots }}
  17. - timeout:2
  18. - attempts:2
  19. - name: add upstream dns servers (only when dnsmasq is not used)
  20. set_fact:
  21. docker_dns_servers: "{{ docker_dns_servers + upstream_dns_servers|default([]) }}"
  22. when: dns_mode == 'kubedns'
  23. - name: add global searchdomains
  24. set_fact:
  25. docker_dns_search_domains: "{{ docker_dns_search_domains + searchdomains|default([]) }}"
  26. - name: check system nameservers
  27. shell: grep "^nameserver" /etc/resolv.conf | sed 's/^nameserver\s*//'
  28. changed_when: False
  29. register: system_nameservers
  30. check_mode: no
  31. - name: check system search domains
  32. shell: grep "^search" /etc/resolv.conf | sed 's/^search\s*//'
  33. changed_when: False
  34. register: system_search_domains
  35. check_mode: no
  36. - name: add system nameservers to docker options
  37. set_fact:
  38. docker_dns_servers: "{{ docker_dns_servers | union(system_nameservers.stdout_lines) | unique }}"
  39. when: system_nameservers.stdout != ""
  40. - name: add system search domains to docker options
  41. set_fact:
  42. docker_dns_search_domains: "{{ docker_dns_search_domains | union(system_search_domains.stdout.split(' ')|default([])) | unique }}"
  43. when: system_search_domains.stdout != ""
  44. - name: check number of nameservers
  45. fail: msg="Too many nameservers"
  46. when: docker_dns_servers|length > 3
  47. - name: check number of search domains
  48. fail: msg="Too many search domains"
  49. when: docker_dns_search_domains|length > 6
  50. - name: check length of search domains
  51. fail: msg="Search domains exceeded limit of 256 characters"
  52. when: docker_dns_search_domains|join(' ')|length > 256