main.yml 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. ---
  2. # Loading vars
  3. - name: Add the OS specific varibles
  4. include_vars: "{{ ansible_os_family }}.yml"
  5. # Install DHCP server
  6. - name: Install the required packages in Redhat derivatives
  7. yum: name={{ dhcp_server_package }} state=installed
  8. when: ansible_os_family == 'RedHat'
  9. - name: Install the required packages in Debian derivatives
  10. apt: name={{ dhcp_server_package }} state=installed update_cache=yes
  11. when: ansible_os_family == 'Debian'
  12. - name: Install the required packages in ArchLinux derivatives
  13. pacman: name={{ dhcp_server_package }} state=installed update_cache=yes
  14. when: ansible_os_family == 'Archlinux'
  15. # Configuring AppArmor if requested
  16. - name: Check if the /etc/apparmor.d/local folder exists
  17. stat: path=/etc/apparmor.d/local
  18. when: configure_apparmor
  19. register: apparmor_local
  20. - name: Configure AppArmor to allow dhcpd access to temporary ansible files for configuration checking
  21. copy: src=apparmor/usr.sbin.dhcpd dest=/etc/apparmor.d/local/usr.sbin.dhcpd owner=root group=root mode=0644
  22. when: configure_apparmor and apparmor_local.stat.exists
  23. notify:
  24. - restart apparmor
  25. - meta: flush_handlers
  26. # Set desired permissions on /etc/dhcp or use defaults
  27. - name: Set permissions on /etc/dhcp
  28. file: path=/etc/dhcp state=directory mode={{ dhcp_dir_mode | default("0750") }}
  29. when: "ansible_os_family == 'Debian' or ansible_os_family == 'RedHat'"
  30. # Generate configuration
  31. - name: Generate dhcpd.conf
  32. template: src=dhcpd.conf.j2 dest={{ dhcp_server_config }} owner=root group=root mode=0644 validate='/usr/sbin/dhcpd -t -cf %s'
  33. notify:
  34. - restart dhcpd
  35. # Generate service configuration
  36. - name: Generate DHCP service conf
  37. template: src=service.conf.{{ ansible_os_family }}.j2 dest={{ dhcp_service_config }} owner=root group=root
  38. when: ansible_os_family == 'Debian' or (ansible_os_family == 'RedHat' and ansible_distribution_major_version < '7')
  39. notify:
  40. - restart dhcpd
  41. # Enable DHCP server
  42. - name: Start the dhcp services DHCP
  43. service: name={{ dhcp_service }} state=started enabled=yes