Show posts by author:
Nick Anderson

Feature Friday #3: execresult_as_data()

When you want to inspect both the return code and output from a command execresult_as_data() might be the function you are searching for. Most CFEngine policy writers have used execresult() and returnszero(). They are useful when you want to do something based on the output of a command or based on its successful execution (returning zero). For example: /tmp/feature-friday-3.cf bundle agent __main__ { vars: "hostname" string => execresult( "$(paths.hostname)", "useshell" ); classes: "my_command_returned_zero" expression => returnszero( "$(paths.hostname)", "noshell" ); reports: "$(hostname)"; my_command_returned_zero:: "$(paths.hostname) returned 0"; } command cf-agent --no-lock --log-level info --file /tmp/feature-friday-3.cf output precision-5570 R: precision-5570 R: /bin/hostname returned 0 But, sometimes, you care about specific return codes. However, you might also want to consider the output from a command. execresult_as_data() facilitates inspecting both output and return code from a command’s execution, by returning a data structure. Let’s take a look.

Posted by Nick Anderson
March 29, 2024

Show notes: The agent is in - Episode 35 - Automatic grouping of hosts with select_class

Have you ever wanted some hosts to organize themselves into different groups, but without spending time to worry about assigning a specific group? Cody, Craig, and Nick talk about using the select_class feature in CFEngine. Nick implements automatic assignment of a maintainer for each host: You want to assign a maintainer to each host that should be the primary point of contact. Some hosts should may have a specific maintainer, but generally, you don’t care about the relationship between the person and the actual function of the machine. It’s okay if the groups are not perfectly balanced. First we provide a list of maintainers to select from.

Posted by Nick Anderson
March 28, 2024

Feature Friday #2: $(with)

Ever wanted to manipulate a string - temporarily - for an individual promise? Check out the with attribute and its special, $(with) variable. Sometimes you need some variation on a string for a specific case. Traditionally, to achieve this you’d simply define another variable. Here is a contrived example: I have a string, nginx and I want to emit a report that contains both the string itself and the upper case version of the string.

Posted by Nick Anderson
March 22, 2024

Feature Friday #1: ifelse()

Looking for a way to concisely set a variable conditionally? Have you heard of ifelse()? In CFEngine, traditionally class expressions are used to constrain promises to different contexts. Setting a variable to different values based on context might look like this: /tmp/feature-friday-1.cf bundle agent __main__ { vars: "MyVariable" string => "My Default value"; redhat_8|centos_8|rocky_8:: "MyVariable" string => "My value for EL 8"; ubuntu_22:: "MyVariable" string => "My value for Ubuntu 22"; any:: "MyVariable" string => "My value on Friday", if => "Friday"; reports: "It's $(sys.date) and I am running on $(sys.os_release[PRETTY_NAME])"; "MyVariable is '$(MyVariable)'"; } command cf-agent --no-lock --log-level info --file /tmp/feature-friday-1.cf output R: It's Mon Mar 11 12:36:41 2024 and I am running on Ubuntu 22.04.4 LTS R: MyVariable is 'My value for Ubuntu 22' That’s great, lots of flexibility, but with an increasing number of options the policy can get quite long and it’s easier for a human interpreter to lose track of the context. The same can be achieved in a single statement using ifelse().

Posted by Nick Anderson
March 15, 2024

Feature Friday: A 42-part saga

Last year in commemoration of 30 years of CFEngine I received this lovely coin. I thought it would be fun to celebrate by writing 42 blog posts, each with some little tip about CFEngine. So, be sure to come check in on Friday for the first post in the Feature Friday series. Series Posts ifelse() $(with) execresult_as_data() cf-remote cfbs cf-promises depends_on –bundlesequence body file control - inputs cf-support namespaces special variables classesmatching() variablesmatching() & variablesmatching_as_data() bundlesmatching() host info report Tags for Inventory and Reporting Augments - def.json What variables and classes are defined? Macros Promisees or Stakeholdes Don’t fix, just warn Agent say! Augments - host_specific.json Unprivileged execution Groups custom promise type Multiple outcomes Restricting individual promises using if and unless Variable class expressions Agent svg Seeing a data structure with storejson() Doing math in policy with eval() Why associative arrays when data containers exist? Self organizing groups Groups in Mission Portal Formatting policy with cffmt Decisions based on arbitrary semantic versions Developing modules that take input The power of lists and implicit iteration What would CFEngine do? How can I quote thee, let me count the ways ob-cfengine3

Posted by Nick Anderson
March 11, 2024

Show notes: The agent is in - Episode 34 - Host visibility with containerized CFEngine

Curious about getting visibility of a host where you can’t install CFEngine natively, but can run a container? Craig shows us how he’s getting inventory from his Torizon Verdin IMX8MP by deploying a container with a chroot containing volumes bind mounted from the host. A long post show discussion was had about CfgMgmtCamp as well as a long troubleshooting session dealing with a prickly package management situation. Video The video recording is available on YouTube:

Posted by Nick Anderson
February 29, 2024

Show notes: The agent is in - Episode 33 - Interview with Mark Burgess

The CFEngine team celebrates 30 years of CFEngine and has a chat with Mark Burgess, the original creator and author of CFEngine. Mark delves into the early chapters of his journey, tracing back the roots of his inspiration to science fiction sagas like Star Trek and Dr. Who, and the literary works of Isaac Asimov, Aurthur C. Clarke, and Paul Davies. Mark recalled his first computer, the fabulous, most programmable, decomposable, put back together-able, expandable thing, a BBC-b microcomputer.

Posted by Nick Anderson
January 25, 2024

Show notes: The agent is in - Episode 32 - Fireside chat w/ Mike Weilgart

Curious about how users feel about using CFEngine? Cody and Nick are joined by Mike Weilgart, a long time CFEngine user about his history and how CFEngine compares to other tools he has been using recently. Video The video recording is available on YouTube: At the end of every webinar, we stop the recording for a nice and relaxed, off-the-record chat with attendees. Join the next webinar to not miss this discussion.

Posted by Nick Anderson
December 28, 2023

Show notes: The agent is in - Episode 31 - Sneak peek of CFEngine 3.23

Join the team for a sneak peek of what’s coming in 3.23.0. Herman joins Cody, Craig and Nick to discuss what’s new in the upcoming release of CFEngine 3.23.0. We look at improvements to Groups in Mission Portal with easier ways to specify specific hosts that should or should not be part of the group based on reported attributes. This new functionality makes it much easier to affect change across a set of hosts without touching policy.

Posted by Nick Anderson
November 30, 2023

Change in behavior: ignore_interfaces.rx prefers a new location

ignore_interfaces.rx can be populated with regular expressions that match network interface names. When an interface matches CFEngine will ignore the interface. In the upcoming release of 3.23.0, and in the future release of 3.21.4 there is a change in behavior with respect to the preferred location of ignore_interfaces.rx from $(sys.inputdir) (typically /var/cfengine/inputs) to $(sys.workdir) (typically /var/cfengine). The change from $(sys.inputdir) to $(sys.workdir) makes it easier to ignore different interfaces on different hosts.

Posted by Nick Anderson
November 16, 2023