main.yml 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. ansible.builtin.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. - Reload systemd services
  43. - Restart {{ item }}
  44. - name: Enable dhcpd and unbound services
  45. ansible.builtin.systemd_service:
  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. ansible.builtin.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 isc-dhcp-server
  65. - name: Copy unbound conf files
  66. ansible.builtin.template:
  67. src: "unbound/{{ item }}.j2"
  68. dest: /etc/unbound/unbound.conf.d/{{ item }}
  69. owner: root
  70. group: unbound
  71. mode: '0640'
  72. loop:
  73. - unbound.conf
  74. - local-domain.conf
  75. - plug-onion-addresses.conf
  76. notify:
  77. - Restart unbound
  78. - name: Check adblock config file
  79. ansible.builtin.stat:
  80. path: /etc/unbound/unbound.conf.d/ad-servers.conf
  81. register: adservers_conf
  82. - ansible.builtin.set_fact:
  83. adservers_conf_age_in_days: "{{ (lookup('pipe', 'date +%s')|int - adservers_conf.stat.ctime|int) / 86400 }}"
  84. when:
  85. - adservers_conf.stat.exists
  86. - name: Download fresh adblock config
  87. ansible.builtin.get_url:
  88. url: 'https://pgl.yoyo.org/adservers/serverlist.php?hostformat=unbound&mimetype=plaintext'
  89. dest: /etc/unbound/unbound.conf.d/ad-servers.conf
  90. owner: root
  91. group: unbound
  92. mode: '0644'
  93. when:
  94. - not adservers_conf.stat.exists or adservers_conf_age_in_days|int > 30
  95. notify:
  96. - Restart unbound
  97. - name: Update /etc/hosts
  98. ansible.builtin.template:
  99. src: hosts.j2
  100. dest: /etc/hosts
  101. owner: root
  102. group: root
  103. mode: '0644'