variablesmatching_as_data()
is useful for centralizing information from disparate sources. For example, deriving a list of package names by extracting the values from variables that match a specific name.
bundle agent package_names_from_variablesmatching_as_data
# @brief Example illustrating deriving a list of package names from variables named with a specific naming convention
{
vars:
"packages_baseline" slist => { "bash-completion", "emacs" };
"packages_os" slist => { "httpd" };
"packages_barf" slist => { "apache" };
"_mypkgdata" data => variablesmatching_as_data( ".*\.packages_.*" );
"_v" slist => getvalues( _mypkgdata );
reports:
'$(with)'
with => storejson( _v );
}
bundle agent __main__
{
methods: "finding_vars_by_name";
}
R: [ "bash-completion", "emacs", "httpd", "apache" ]
Or, slightly better, a tag:
bundle agent package_names_from_variablesmatching_as_data
# @brief Example illustrating deriving a list of package names from variables having a specific tag
{
vars:
"packages_baseline"
meta => { "desired_package_names=present" },
slist => { "bash-completion", "emacs" };
"packages_os"
meta => { "desired_package_names=present" },
slist => { "httpd" };
"packages_barf"
meta => { "desired_package_names=present" },
slist => { "apache" };
"_mypkgdata" data => variablesmatching_as_data( ".*", "desired_package_names=present" );
"_v" slist => getvalues( _mypkgdata );
reports:
'$(with)'
with => storejson( _v );
}
bundle agent __main__
{
methods: "finding_vars_by_name";
}
R: [ "bash-completion", "emacs", "httpd", "apache" ]