main.yml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. ---
  2. - name: Set openresolv to not configure /etc/resolv.conf
  3. ansible.builtin.lineinfile:
  4. path: /etc/resolvconf.conf
  5. regexp: '^resolvconf='
  6. line: 'resolvconf=NO'
  7. - name: Configure DNS servers
  8. ansible.builtin.template:
  9. src: resolv.conf.j2
  10. dest: /etc/resolv.conf
  11. owner: root
  12. group: root
  13. mode: '0644'
  14. - name: Install dhcp & dns packages
  15. ansible.builtin.package:
  16. name:
  17. - isc-dhcp-server
  18. - unbound
  19. update_cache: no
  20. state: present
  21. - name: Create custom service folders
  22. ansible.builtin.file:
  23. path: /etc/systemd/system/{{ item }}.service.d
  24. state: directory
  25. owner: root
  26. group: root
  27. mode: '0755'
  28. loop:
  29. - isc-dhcp-server
  30. - unbound
  31. #- name: Make services autorestart themselves on failure
  32. # template:
  33. # src: "custom-service-autorestart.j2"
  34. ## dest: /etc/systemd/system/{{ item }}.service.d/autorestart.conf
  35. # owner: root
  36. # group: root
  37. # mode: '0644'
  38. # loop:
  39. # - isc-dhcp-server
  40. # - unbound
  41. # notify:
  42. # - Restart {{ item }}
  43. # - Reload systemd services
  44. - name: Enable dhcpd and unbound services
  45. systemd:
  46. name: "{{ item }}"
  47. enabled: yes
  48. loop:
  49. - isc-dhcp-server
  50. - unbound
  51. - name: Set dhcp to only run via ipv4
  52. ansible.builtin.lineinfile:
  53. path: /etc/default/isc-dhcp-server
  54. regexp: '^INTERFACESv4='
  55. line: 'INTERFACESv4="{{ dhcp_interface }}"'
  56. - name: Copy dhcpd.conf
  57. template:
  58. src: dhcpd/dhcpd.conf.j2
  59. dest: /etc/dhcp/dhcpd.conf
  60. owner: root
  61. group: root
  62. mode: '0644'
  63. notify:
  64. - Restart dhcpd
  65. #- name: Create unbound local.d directory
  66. # ansible.builtin.file:
  67. # path: /etc/unbound/local.d
  68. # state: directory
  69. # owner: root
  70. # group: unbound
  71. # mode: '0750'
  72. - name: Copy unbound conf files
  73. template:
  74. src: "unbound/{{ item }}.j2"
  75. dest: /etc/unbound/unbound.conf.d/{{ item }}
  76. owner: root
  77. group: unbound
  78. mode: '0640'
  79. loop:
  80. - unbound.conf
  81. - local-domain.conf
  82. - plug-onion-addresses.conf
  83. notify:
  84. - Restart unbound
  85. - name: Check adblock config file
  86. stat:
  87. path: /etc/unbound/unbound.conf.d/ad-servers.conf
  88. register: adservers_conf
  89. - set_fact:
  90. adservers_conf_age_in_days: "{{ (lookup('pipe', 'date +%s')|int - adservers_conf.stat.ctime|int) / 86400 }}"
  91. when:
  92. - adservers_conf.stat.exists
  93. - name: Download fresh adblock config
  94. get_url:
  95. url: 'https://pgl.yoyo.org/adservers/serverlist.php?hostformat=unbound&mimetype=plaintext'
  96. dest: /etc/unbound/unbound.conf.d/ad-servers.conf
  97. owner: root
  98. group: unbound
  99. mode: '0644'
  100. when:
  101. - not adservers_conf.stat.exists or adservers_conf_age_in_days|int > 30
  102. notify:
  103. - Restart unbound
  104. - name: Update /etc/hosts
  105. template:
  106. src: hosts.j2
  107. dest: /etc/hosts
  108. owner: root
  109. group: root
  110. mode: '0644'