diff --git a/dhcpcd.yml b/dhcpcd.yml new file mode 100644 index 0000000..e4bb20f --- /dev/null +++ b/dhcpcd.yml @@ -0,0 +1,3 @@ +- hosts: dhcpcd + roles: + - dhcpcd diff --git a/roles/dhcpcd/defaults/main.yml b/roles/dhcpcd/defaults/main.yml new file mode 100644 index 0000000..a6264b6 --- /dev/null +++ b/roles/dhcpcd/defaults/main.yml @@ -0,0 +1,13 @@ +dhcpcd_send_hostname: true +dhcpcd_use_clientid: false +dhcpcd_persistent: true +dhcpcd_rapid_commit: true +dhcpcd_options: '{{ dhcpcd_default_options }}' +dhcpcd_ntp_servers: true +dhcpcd_interface_mtu: true +dhcpcd_require_server_id: true +dhcpcd_slaac_private: true +dhcpcd_noipv4ll: false +dhcpcd_noipv4: false +dhcpcd_noipv6rs: false +dhcpcd_interfaces: [] diff --git a/roles/dhcpcd/handlers/main.yml b/roles/dhcpcd/handlers/main.yml new file mode 100644 index 0000000..6cd19fe --- /dev/null +++ b/roles/dhcpcd/handlers/main.yml @@ -0,0 +1,4 @@ +- name: restart dhcpcd + service: + name=dhcpcd + state=restarted diff --git a/roles/dhcpcd/tasks/main.yml b/roles/dhcpcd/tasks/main.yml new file mode 100644 index 0000000..be10c73 --- /dev/null +++ b/roles/dhcpcd/tasks/main.yml @@ -0,0 +1,21 @@ +- name: ensure dhcpcd is installed + package: + name=dhcpcd + state=present + +- name: ensure dhcpcd is configured + template: + src=dhcpcd.conf.j2 + dest=/etc/dhcpcd.conf + mode=0644 + notify: restart dhcpcd + +- name: ensure dhcpcd starts at boot + service: + name=dhcpcd + enabled=yes +- meta: flush_handlers +- name: ensure dhcpcd is running + service: + name=dhcpcd + state=started diff --git a/roles/dhcpcd/templates/dhcpcd.conf.j2 b/roles/dhcpcd/templates/dhcpcd.conf.j2 new file mode 100644 index 0000000..ee26d45 --- /dev/null +++ b/roles/dhcpcd/templates/dhcpcd.conf.j2 @@ -0,0 +1,112 @@ +# A sample configuration for dhcpcd. +# See dhcpcd.conf(5) for details. + +# Allow users of this group to interact with dhcpcd via the control socket. +{% if dhcpcd_controlgroup is defined %} +controlgroup {{ dhcpcd_controlgroup }} +{% else %} +#controlgroup wheel +{% endif %} +{% if dhcpcd_allow_interfaces is defined %} + +allowinterfaces {{ dhcpcd_allow_interfaces }} +{% endif %} +{% if dhcpcd_deny_interfaces is defined %} + +denyinterfaces {{ dhcpcd_deny_interfaces }} +{% endif %} + +# Inform the DHCP server of our hostname for DDNS. +{% if dhcpcd_send_hostname|bool %} +hostname +{% else %} +#hostname +{% endif %} + +# Use the hardware address of the interface for the Client ID. +{% if dhcpcd_use_clientid|bool %} +clientid +{% else %} +#clientid +{% endif %} +# or +# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361. +# Some non-RFC compliant DHCP servers do not reply with this set. +# In this case, comment out duid and enable clientid above. +{% if not dhcpcd_use_clientid|bool %} +duid +{% else %} +#duid +{% endif %} + +# Persist interface configuration when dhcpcd exits. +{% if dhcpcd_persistent|bool %} +persistent +{% else %} +#persistent +{% endif %} + +# Rapid commit support. +# Safe to enable by default because it requires the equivalent option set +# on the server to actually work. +{% if dhcpcd_rapid_commit|bool %} +option rapid_commit +{% else %} +#option rapid_commit +{% endif %} + +# A list of options to request from the DHCP server. +{% for option in dhcpcd_options %} +option {{ option }} +{% endfor %} +# Most distributions have NTP support. +{% if dhcpcd_ntp_servers|bool %} +option ntp_servers +{% else %} +#option ntp_servers +{% endif %} +# Respect the network MTU. This is applied to DHCP routes. +{% if dhcpcd_interface_mtu|bool %} +option interface_mtu +{% else %} +#option interface_mtu +{% endif %} + +# A ServerID is required by RFC2131. +{% if dhcpcd_require_server_id|bool %} +require dhcp_server_identifier +{% else %} +#require dhcp_server_identifier +{% endif %} + +# Generate Stable Private IPv6 Addresses instead of hardware based ones +{% if dhcpcd_slaac_private|bool %} +slaac private +{% else %} +#slaac private +{% endif %} +{% if dhcpcd_noipv4ll|bool %} + +# Disable IPv4 link-local address automatic configuration (APIPA) +noipv4ll +{% endif %} +{% if dhcpcd_noipv4|bool %} + +# Disable IPv4 configuration entirely +noipv4 +{% endif %} +{% if dhcpcd_noipv6rs|bool %} + +# Disable IPv6 router solicitations +noipv6rs +{% endif %} +{% for iface in dhcpcd_interfaces %} + +{% if iface.description is defined %} +# {{ iface.description }} +{% endif %} +interface {{ iface.name }} +{% for setting in iface.config %} + {{ setting }} +{% endfor %} +{% endfor %} diff --git a/roles/dhcpcd/vars/main.yml b/roles/dhcpcd/vars/main.yml new file mode 100644 index 0000000..4bcb6dd --- /dev/null +++ b/roles/dhcpcd/vars/main.yml @@ -0,0 +1,3 @@ +dhcpcd_default_options: +- domain_name_servers, domain_name, domain_search, host_name +- classless_static_routes