Skip to content

Instantly share code, notes, and snippets.

@nickanderson
Created October 27, 2022 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickanderson/ac6182f1d199c74369f026490a6448ab to your computer and use it in GitHub Desktop.
Save nickanderson/ac6182f1d199c74369f026490a6448ab to your computer and use it in GitHub Desktop.
Example expanding interface name in classic cfengine template for Sparky in #cfengine on irc.libera.chat
### Managed by CFEngine
$(sys.ipv4) is on $(sys.ip2iface[$(sys.ipv4)])
bundle agent __main__
{
  files:
      "/tmp/example.txt"
        create => "true", # This will ensure the file is present, if template expansion fails, you might have an empty file
        template_method => "cfengine", # This is the default, but not necessarily preffered
        edit_template => "/tmp/example.tpl";
  reports:
    "/tmp/example.txt"
      printfile => cat( $(this.promiser) );
}
    info: Created file '/tmp/example.txt', mode 0600
    info: Inserted the promised line '### Managed by CFEngine' into '/tmp/example.txt' after locator
    info: insert_lines promise '### Managed by CFEngine' repaired
    info: Inserted the promised line '192.168.42.232 is on wlp0s20f3' into '/tmp/example.txt' after locator
    info: insert_lines promise '192.168.42.232 is on wlp0s20f3' repaired
    info: Edited file '/tmp/example.txt'
R: /tmp/example.txt
R: ### Managed by CFEngine
R: 192.168.42.232 is on wlp0s20f3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment