Xander Cage writes:
#!/var/cfengine/bin/cf-agent -KI
#body common control #{ # bundlesequence => { "b0026_manage_aixtoolbox" }; # inputs => { # "$(sys.libdir)/stdlib.cf", # "$(sys.inputdir)/itsv/itsv_common_lib.cf", # "$(sys.inputdir)/itsv/hostgroups.cf", # "$(sys.inputdir)/itsv/itsv_stanza_lib.cf", # }; #} # ## would be nicer with regex ("ITSV_ABORT.*") - but Bug prevents this .. #body agent control { # abortbundleclasses => { "ITSV_BUNDLE_ABORT" }; # abortclasses => { "ITSV_ABORT" }; #}
bundle agent b0026_manage_aixtoolbox { # # promise to manage aixtoolbox rpm packages # and yum repo configs
meta: "tags" slist => { "itsv" }; methods: !am_policy_hub:: "do the rpm walk" usebundle => manage_aixtoolbox, ifvarclass => "SPARE_DAILY", action => if_elapsed_day; } bundle agent manage_aixtoolbox { classes: "RPM_ROLLOUT_PLATFORM" expression => or("aix_7_1", "aix_7_2")
;
Nick Anderson writes:
You didn't ask but …
,-—
#!/var/cfengine/bin/cf-agent -KI #body common control #{ # bundlesequence => { "b0026_manage_aixtoolbox" }; # inputs => { # "$(sys.libdir)/stdlib.cf", # "$(sys.inputdir)/itsv/itsv_common_lib.cf", # "$(sys.inputdir)/itsv/hostgroups.cf", # "$(sys.inputdir)/itsv/itsv_stanza_lib.cf", # }; #}
Instead of keeping these stubs for direct execution which need to be commented/uncommented, perhaps consider leveraging body file control and bundle agent main.
# ## would be nicer with regex ("ITSV_ABORT.*") - but Bug prevents this .. #body agent control { # abortbundleclasses => { "ITSV_BUNDLE_ABORT" }; # abortclasses => { "ITSV_ABORT" }; #}
Is that still true for you?
When I search the tracker I find CFE-223, CFE-961, and CFE-1874 which are all closed.
bundle agent b0026_manage_aixtoolbox { # # promise to manage aixtoolbox rpm packages # and yum repo configs meta: "tags" slist => { "itsv" }; methods: !am_policy_hub:: "do the rpm walk" usebundle => manage_aixtoolbox, ifvarclass => "SPARE_DAILY",
These days if is preferred over ifvarclass.
Personally I am not a fan of the if_ok classes body.
body classes if_ok(x) # @brief Define the class `x` if the promise is kept or could be repaired # @param x The name of the class that should be defined { promise_repaired => { "$(x)" }; promise_kept => { "$(x)" }; }
It's a bit of a misnomer. As you can see it defines the class if the promise is either kept or repaired. But promises can have multiple outcomes, and this doesn't really account for that.
This example illustrates a case where a single promise is both kept and notkept at the same time.
#!/var/cfengine/bin/cf-agent -f- body file control { inputs => { '$(sys.libdir)/stdlib.cf' }; } bundle agent example_multiple_outcomes { classes: "running_as_root" expression => strcmp( "$(sys.user_data[uid])", "0" ); files: running_as_root:: "/tmp/immutable" create => "true", handle => "init_immutable", edit_line => example_edit_line("Initalized file"), classes => results("bundle", "my_id_init"), unless => fileexists( "/tmp/immutable" ); "/tmp/immutable" create => "true", edit_line => example_edit_line("Modify"), classes => results("bundle", "my_id_modify"), depends_on => { "file_immutable" }; commands: running_as_root:: "chattr +i /tmp/immutable" handle => "file_immutable", contain => in_shell, depends_on => { "init_immutable" }; vars: running_as_root:: "classes" slist => classesmatching(".*my_id.*"); reports: !running_as_root:: "You need to run this example as root in order for the immutable file to be created"; running_as_root:: "Found Class = '$(classes)'"; } bundle edit_line example_edit_line(str) { insert_lines: "$(sys.date) $(str)"; } bundle agent __main__{methods:"example_multiple_outcomes";}
exec 2>&1 cf-agent -KIf /tmp/multiple-outcomes.cf :
info: Created file '/tmp/immutable', mode 0600
info: Inserted the promised line 'Thu Jan 28 10:54:50 2021 Initalized file' into '/tmp/immutable' after locator
info: insert_lines promise 'Thu Jan 28 10:54:50 2021 Initalized file' repaired
info: Edited file '/tmp/immutable'
info: files promise '/tmp/immutable' repaired
info: Executing 'no timeout' ... 'chattr +i /tmp/immutable'
info: Completed execution of 'chattr +i /tmp/immutable'
info: Inserted the promised line 'Thu Jan 28 10:54:50 2021 Modify' into '/tmp/immutable' after locator
info: insert_lines promise 'Thu Jan 28 10:54:50 2021 Modify' repaired
error: Can't rename '/tmp/immutable.cf-after-edit' to '/tmp/immutable' - so promised edits could not be moved into place. (rename: Operation not permitted)
error: Unable to save file '/tmp/immutable' after editing
error: Errors encountered when actuating files promise '/tmp/immutable'
R: Found Class = 'my_id_init_repaired'
R: Found Class = 'my_id_init_reached'
R: Found Class = 'my_id_modify_failed'
R: Found Class = 'my_id_modify_not_kept'
R: Found Class = 'my_id_modify_error'
R: Found Class = 'my_id_modify_kept'
R: Found Class = 'my_id_modify_reached'
error: Method 'example_multiple_outcomes' failed in some repairs
reports: YUM_INSTALL_OK:: "YUM UPGRADED SOME PACKAGES, SEE /var/log/yum.log";
Are you familiar with printfile bodies?
bundle agent example_printfile(file) { reports: "The first two lines of '$(file)':" printfile => head_n( $(file), 2 ); "The full content of '$(file)'" printfile => cat( $(file) ); } bundle agent __main__ { methods: "Print Self" usebundle => example_printfile($(this.promise_filename)); }
R: The first two lines of '/home/nickanderson/org/cfengine3-gPoHAy':
R: body file control{ inputs => { '$(sys.libdir)/stdlib.cf' };}
R: bundle agent example_printfile(file)
R: The full content of '/home/nickanderson/org/cfengine3-gPoHAy'
R: body file control{ inputs => { '$(sys.libdir)/stdlib.cf' };}
R: bundle agent example_printfile(file)
R: {
R: reports:
R: "The first two lines of '$(file)':"
R: printfile => head_n( $(file), 2 );
R:
R: "The full content of '$(file)'"
R: printfile => cat( $(file) );
R: }
R: bundle agent __main__
R: {
R: methods:
R: "Print Self"
R: usebundle => example_printfile($(this.promise_filename));
R: }
For this I guess it would be nice to be able to print the end of the file instead of the whole thing or just the beginning of the file. I created CFE-3558 maybe someone will be nice enough to implement it for us.
Xander Cage writes:
i use the yum package module to manage rpm installs. works well so far, but one thing bothers me. i want to report which packages are going to be
It's not clear to me exactly what your looking for but two things come to mind.

--
You received this message because you are subscribed to the Google Groups "help-cfengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to help-cfengin...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/help-cfengine/d9e5e451-9f66-4a1f-8d7f-f9dfc6546588n%40googlegroups.com.
Xander Cage writes:
i messed around with action_policy and packagesupdatemathing(), looked promising at first sight, but i was unable to to figure out how to integrate this in my policy, way to complicated for my poor little brain, thanks anyway.
What specifically did you find complicated?
packageupdatesmatching()?The basic steps are:
packageupdatesmatching() returns an array of dicts, so we need to pull an index that we can use to iterate over the datastructure.nop is used.body file control { inputs => { "$(sys.libdir)/stdlib.cf" }; } body common control { package_module => "$(package_module_knowledge.platform_default)"; package_inventory => { $(package_module_knowledge.platform_default) }; } bundle agent example_packages_version_latest_warn_classes { vars: # Get a datastructure containing information about package updates that are available "_package_updates" data => packageupdatesmatching( ".*", ".*", ".*", ".*" ); # packageupdatesmatching() returns an array of dicts, we need to pull the index for iteration "_updates_available" slist => getindices( @(_package_updates) ); # Build a classic array of the packages that have updates available # Key on package name, value being the version available for install "_update_available[$(_package_updates[$(_updates_available)][name])]" string => "$(_package_updates[$(_updates_available)][version])"; "_packages_upgradeable" slist => getindices( _update_available ); packages: "$(_packages_upgradeable)" policy => "present", version => "latest", action => policy( "warn" ), classes => results( "bundle", "my_pkg_$(_packages_upgradeable)"); reports: "$(_packages_upgradeable) can be upgraded to version '$(_update_available[$(_packages_upgradeable)])'"; "Classes defined as result of packages promise:$(const.n)$(const.t)$(with)" with => join( "$(const.n)$(const.t)", classesmatching( "my_pkg_.*" ) ); } bundle agent __main__ { methods: "example_packages_version_latest_warn_classes"; }
Should result in output something like this:
warning: Package 'wireshark' should be installed
R: wireshark can be upgraded to version '1.10.14-25.el7'
my_pkg_wireshark_failed
my_pkg_wireshark_not_kept
my_pkg_wireshark_error
my_pkg_wireshark_reached
Xander Cage writes:
tested further…i changed nimclient to yum in packages.cf to yum.
aix:: "platform_default" string => "yum";
now it shows some sings of success…but alaso a lot of error messages
root@aixtest01: /root # /var/cfengine/bin/cf-agent -KI -f ./manage_aixtoolbox_new.cf … error: Invalid or missing arguments in package_module body 'yum': query_installed_ifelapsed = -678 query_updates_ifelapsed = -678
Yeah, those values aren't being set. They should be set when you use the full MPF. For my standalone test I also dropped a def.json next to the policy file to set those values.
{ "vars": { "package_module_query_installed_ifelapsed": "0", "package_module_query_updates_ifelapsed": "0" } }
Nick Anderson writes:
Yeah, those values aren't being set. They should be set when you use the full MPF. For my standalone test I also dropped a def.json next to the policy file to set those values.
,-— | { | "vars": { | "package_module_query_installed_ifelapsed": "0", | "package_module_query_updates_ifelapsed": "0" | } | } `-—
Also, this was changed recently so that you don't have to do that if your loading packages.cf.