Skip to content

Instantly share code, notes, and snippets.

@nickanderson
Forked from gbkersey/app_dhcpd.cf
Last active December 10, 2015 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickanderson/4453784 to your computer and use it in GitHub Desktop.
Save nickanderson/4453784 to your computer and use it in GitHub Desktop.
bundle agent app_dhcpd
{
classes:
"any" expression => regextract(
"([^\n]+)\.([^\n]+)\.([^\n]+)",
"$(sys.ipv4_3[eth0])",
"ip_addr"
);
vars:
"repo" string => "/var/cfengine/configfiles";
fs::
"install_packages" slist => {
"dhcp-server"
};
"svc_states[dhcpd]" string => "on";
"services" slist => getindices("svc_states");
"dns_server_to_update" string => "127.0.0.1", policy => "overridable";
"reverse_zone_to_update" string => "$(app_dhcpd.ip_addr[3]).$(app_dhcpd.ip_addr[2]).$(app_dhcpd.ip_addr[1])";
fs_vircio_com::
"dns_server_to_update" string => "10.1.7.4";
fs::
"dhcpd_conf" string =>
"# This file is generated by CFEngine.
ddns-domainname \"$(sys.domain)\";
ddns-updates off;
ddns-update-style interim;
include \"/etc/rndc.key\";
zone $(sys.domain). {
primary $(dns_server_to_update);
key rndc-key;
}
zone $(reverse_zone_to_update).in-addr.arpa. {
primary $(dns_server_to_update);
key rndc-key;
}
# EOF
";
packages:
SuSE::
"$(install_packages)"
comment => "Install base packages.",
package_policy => "add",
package_method => zypper;
methods:
"any" usebundle => service_startup("$(services)","$(svc_states[$(services)])");
files:
fs::
"/etc/sysconfig/dhcpd"
comment => "Bind dhcpd to eth0 and include files",
edit_line => replace_or_add("DHCPD_INTERFACE=\"\"","DHCPD_INTERFACE=\"eth0\"");
"/etc/dhcpd.conf"
comment => "Generate the dhcpd.conf",
edit_line => append_if_no_line("$(dhcpd_conf)"),
edit_defaults => empty,
classes => if_repaired("restart_dhcpd");
"/etc/dhcpd.d/dhcpd-leases.conf"
comment => "Copy dhcpd-leases.conf from the central repository",
copy_from => secure_cp("$(repo)/etc/dhcpd.d/dhcpd-leases.conf.$(sys.fqhost)","$(sys.policy_hub)"),
perms => mog("0644", "root", "root"),
classes => if_repaired("restart_dhcpd");
}
Output from this policy...
# This file is generated by CFEngine.
ddns-domainname "vircio.com";
ddns-updates off;
ddns-update-style interim;
include "/etc/rndc.key";
zone vircio.com. {
primary 10.1.7.4;
key rndc-key;
}
zone $(app_dhcpd.ip_addr[3]).$(app_dhcpd.ip_addr[2]).$(app_dhcpd.ip_addr[1]).in-addr.arpa. {
primary 10.1.7.4;
key rndc-key;
}
# EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment