Skip to content

Instantly share code, notes, and snippets.

@gbkersey
Created January 5, 2013 15:12
Show Gist options
  • Save gbkersey/4462033 to your computer and use it in GitHub Desktop.
Save gbkersey/4462033 to your computer and use it in GitHub Desktop.
bundle agent app_dhcpd
{
classes:
"any" expression => regextract(
"([^\n]+)\.([^\n]+)\.([^\n]+)",
"$(sys.ipv4_3[$(interface)])",
"ip_addr"
);
vars:
"repo" string => "/var/cfengine/configfiles";
"templ_dir" string => "/var/cfengine/inputs/templates";
"interface" string => "eth0",
policy => "overridable";
"dns_server_to_update" string => "127.0.0.1",
policy => "overridable";
"router" string => "$(sys.ipv4_3[$(interface)]).254",
policy => "overridable";
"domain_name_servers" string => "$(sys.ipv4[$(interface)]), $(sys.ipv4_3[$(interface)]).254",
policy => "overridable";
fs::
"install_packages" slist => {
"dhcp-server"
};
"svc_states[dhcpd]" string => "on";
"services" slist => getindices("svc_states");
"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";
"router" string => "$(sys.ipv4_3[$(interface)]).253";
"domain_name_servers" string => "10.1.7.4, 10.1.7.6";
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 => "Generate /etc/sysconfig/dhcpd from the template.",
create => "true",
edit_template => "$(templ_dir)/etc/sysconfig/dhcpd.tmpl",
classes => if_repaired("restart_dhcpd");
"/etc/dhcpd.conf"
comment => "Generate the dhcpd.conf from the template",
create => "true",
edit_template => "$(templ_dir)/etc/dhcpd.conf.tmpl",
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");
commands:
fs.restart_dhcpd.!stop_dhcpd::
"/etc/init.d/dhcpd restart"
comment => "Restart dhcpd if the configuration files are changed.";
processes:
fs::
"/sbin/dhcpcd "
comment => "If dhcpcd is running we are not in place, don't run dhcpd.",
restart_class => "stop_dhcpd",
process_stop => "/etc/init.d/dhcpd stop";
fs.!stop_dhcpd::
"/usr/sbin/dhcpd "
comment => "Make sure dhcpd is running.",
restart_class => "restart_dhcpd";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment