Skip to content

Instantly share code, notes, and snippets.

@neilhwatson
Created October 3, 2014 17:37
Show Gist options
  • Select an option

  • Save neilhwatson/db17a2628af15629c71a to your computer and use it in GitHub Desktop.

Select an option

Save neilhwatson/db17a2628af15629c71a to your computer and use it in GitHub Desktop.
Alternative package promising with CFEngine
body common control
{
bundlesequence => { "main", };
}
bundle agent main
{
vars:
'packages' string => "
any ;; nano ;; install
any ;; pico ;; install
any ;; foobar ;; remove
";
methods:
"any" usebundle => efl_packages( "${packages}" );
}
bundle agent efl_packages( ref )
{
meta:
'Purpose' string => "promise packages";
vars:
"dim_packages"
comment => "Read data to be used in method promises.",
int => parsestringarrayidx(
"pack_o",
"${ref}",
"${efl_c.comment}",
"${efl_c.array_delimiter}",
"${efl_c.max_num}",
"${efl_c.max_bytes}"
);
"i" slist => getindices( "pack_o" );
"install[${pack_o[${i}][1]}]"
string => "install this package",
ifvarclass => "install_package_${i}";
"remove[${pack_o[${i}][1]}]"
string => "remove this package",
ifvarclass => "remove_package_${i}";
build_batch_install_list::
"pkgs_to_install" slist => getindices( "install" );
"install_batch" string => join( " ", "pkgs_to_install" );
build_batch_remove_list::
"pkgs_to_remove" slist => getindices( "remove" );
"remove_batch" string => join( " ", "pkgs_to_remove" );
classes:
"install_package_${i}"
ifvarclass => "${pack_o[${i}][0]}",
expression => strcmp( "install", "${pack_o[${i}][2]}" );
"remove_package_${i}"
ifvarclass => "${pack_o[${i}][0]}",
expression => strcmp( "remove", "${pack_o[${i}][2]}" );
"build_batch_install_list"
expression => classmatch( "install_package_.*" );
"build_batch_remove_list"
expression => classmatch( "remove_package_.*" );
"install_batch"
expression => isvariable( "install_batch" );
"remove_batch"
expression => isvariable( "remove_batch" );
reports:
install_batch::
'pkg_manager install <switches> ${install_batch}';
remove_batch::
'pkg_manager remove <switches> ${remove_batch}';
}
bundle common efl_c
{
meta:
"purpose" string => "Common configs for all EFL bundles";
vars:
#
# Configs for reading data files
#
"cache"
comment => "Location for agent to cache template and other temp files",
string => "/var/cache/cfengine";
"class"
comment => "Regex to extract class name from parameter file name.",
string => ".*?-(\w+)\.txt";
"comment"
comment => "Comment string in data file.",
string => "\s*#[^\n]*";
"array_delimiter"
comment => "Field delimiter for CSV data files read by readstringarrayidx",
string => "\s*;;\s*";
"slist_delimiter"
comment => "Field delimiter for CSV data files read by readstringlist",
string => "\s";
"max_num"
comment => "Maximum number of lines to read from data file",
int => "500";
"max_bytes"
comment => "Maximum number of bytes to read from data file.",
string => "1M";
#
# Delta Reporting configs
#
"logdir"
comment => "Log dir for Delta Reporting logs",
string => "${sys.workdir}/delta_reporting/log";
"promise_log"
comment => "Location for experimental promise outcome log.",
string => "${logdir}/promises";
"udate"
comment => "Date stamp to match agent output",
string => strftime( "localtime", "%Y-%m-%dT%H:%M:%S%z", now() );
#
# Misc vars
#
"efl_server_txt"
comment => "Server access rules parameter file",
# NOTE Access file must be hardcoded because server bundles do not accept arguments.
string => "${sys.workdir}/inputs/efl_data/bundle_params/efl_server.txt";
reports:
debug::
"policy_servers => ${policy_servers}"
comment => "Set debug to see debugging reports";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment