Created
April 11, 2011 13:34
-
-
Save jlgreer/913516 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################ | |
# | |
# Administers version control (Subversion) for Cfengine 3 | |
# | |
################################################################################ | |
# If it does not exist, create an SVN repository $(repo) at $(path) as user | |
# $(user), and set up base dirs branches,tags,trunk. | |
bundle agent initializeSvnRepo(repo, path, user) { | |
classes: | |
"repository_exists" expression => fileexists("$(path)/$(repo)"); | |
reports: | |
!repository_exists:: | |
"repository does not exist: $(repo). Attempting to create it."; | |
commands: | |
!repository_exists:: | |
"/usr/bin/svnadmin create $(path)/$(repo) && \ | |
/usr/bin/svn mkdir -m 'initial setup' file://$(path)/$(repo)/{branches,tags,trunk}" | |
contain => container_std("$(user)", true), | |
action => actionsettings_fix_inform("verbose"); | |
} | |
bundle agent cfgMgtVcs { | |
vars: | |
"fileserver" slist => { @(var.fileserver) }; | |
"masterfiles" string => "$(var.masterfiles)"; | |
"secrets" string => "/var/cfengine/masterfiles/dcsunix/cfgMgtVcs/pri"; | |
"prefix" string => "/var/cfengine/masterfiles/dcsunix/cfgMgtVcs/pub"; | |
"svn_sticky_dirs" slist => { "httpdincludes", "repos", "svnacls", "svnlogs" }; | |
"repo_store" string => "/data01/svn"; | |
"dav_cfg_dir" string => "$(repo_store)/httpdincludes"; | |
"svn_acl_dir" string => "$(repo_store)/svnacls"; | |
"svn_user" string => "svn"; | |
"repositories" slist => { "cf3dcsunix", "cf3unixsys", "cf3shared" }; | |
classes: | |
"chkconfig_httpd_on" expression => | |
returnszero("/sbin/chkconfig --level 3 httpd", "noshell"); | |
methods: | |
CfgMgtVcs:: | |
"initialize_repositories" | |
usebundle => initializeSvnRepo("$(repositories)", "$(repo_store)/repos", "$(svn_user)"); | |
files: | |
CfgMgtVcs:: | |
"$(repo_store)/." | |
create => "true", | |
perms => mode_owner_group("0755", "$(svn_user)", "$(svn_user)"), | |
action => actionsettings_fix_inform("inform"); | |
"$(repo_store)/$(svn_sticky_dirs)/." | |
create => "true", | |
perms => mode_owner_group("2755", "$(svn_user)", "$(svn_user)"), | |
action => actionsettings_fix_inform("inform"); | |
"/etc/httpd/conf.d/auth_ldap.conf" | |
perms => mode_owner_group("0644", "root", "root"), | |
copy_from => copy_std("$(secrets)/etc/httpd/conf.d/auth_ldap.conf", | |
"@(fileserver)", "false", "timestamp"), | |
classes => if_repaired("httpd_reload"), | |
action => actionsettings_fix_inform("inform"); | |
"$(dav_cfg_dir)/cfgmgtsvn-prd-$(repositories).conf" | |
perms => mode_owner_group("0444", "$(svn_user)", "$(svn_user)"), | |
create => "true", | |
edit_line => template("$(prefix)/$(dav_cfg_dir)/master.conf", | |
"__repository__", "$(repositories)"), | |
edit_defaults => empty, | |
classes => if_repaired("httpd_reload"), | |
action => actionsettings_fix_inform("inform"); | |
"/etc/httpd/conf/httpd.conf" | |
perms => mode_owner_group("0644", "root", "root"), | |
copy_from => copy_std("$(prefix)/etc/httpd/conf/httpd.conf", | |
"@(fileserver)", "false", "timestamp"), | |
classes => if_repaired("httpd_reload"), | |
action => actionsettings_fix_inform("inform"); | |
"$(svn_acl_dir)" | |
copy_from => copy_std("$(prefix)/$(svn_acl_dir)", | |
"$(fileserver)", "false", "timestamp"), | |
depth_search => searchsettings_exclude("inf", "/.*/.svn", "false"), | |
file_select => files_matching_not_leaf("@(var.rcs_metadata)", | |
"@(var.filetype_all)"), | |
classes => if_repaired("httpd_reload"), | |
perms => mode_owner_group("0644", "$(svn_user)", "$(svn_user)"), | |
action => actionsettings_fix_inform("inform"); | |
commands: | |
# Careful here - negated class. Make sure it's protected by compounding it with | |
# classes that apply to this case | |
CfgMgtVcs.!chkconfig_httpd_on:: | |
"/sbin/chkconfig httpd on" | |
contain => container_std("root", false), | |
action => actionsettings_fix_inform_noisylogs("inform"); | |
# move this to main | |
CfgMgtVcs.httpd_reload:: | |
"/etc/init.d/httpd reload" | |
contain => container_std("root", true), | |
action => actionsettings_fix_inform("verbose"); | |
CfgMgtVcs:: | |
"/usr/bin/yum -y install httpd" | |
contain => container_std("root", true), | |
action => actionsettings( "fix", "720", "2", "inform", "false", "false", "inform"); | |
"/usr/bin/yum -y install mod_dav_svn" | |
contain => container_std("root", true), | |
action => actionsettings( "fix", "720", "2", "inform", "false", "false", "inform"); | |
"/usr/bin/yum -y install mod_ssl" | |
contain => container_std("root", true), | |
action => actionsettings( "fix", "720", "2", "inform", "false", "false", "inform"); | |
} | |
# Lifted from reference guide | |
body replace_with value(x) | |
{ | |
replace_value => "$(x)"; | |
occurrences => "all"; | |
} | |
# Simple proof of concept for templatization | |
bundle edit_line template(templatefile, search, replace) | |
{ | |
insert_lines: | |
"$(templatefile)" | |
insert_type => "file", | |
comment => "Expand variables in the template file"; | |
# This appears only to work for Cfengine special variables? | |
# expand_scalars => "true"; | |
replace_patterns: | |
"$(search)" | |
replace_with => value("$(replace)"); | |
} | |
body edit_defaults empty | |
{ | |
empty_file_before_editing => "true"; | |
edit_backup => "false"; | |
max_file_size => "300000"; | |
} | |
bundle edit_line search_replace(search, replace) { | |
replace_patterns: | |
"$(search)" | |
replace_with => replace_std("$(replace)"); | |
} | |
body replace_with replace_std(value) { | |
replace_value => "$(value)"; | |
occurrences => "all"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment