This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#this requires cfengine 3.7 for the if and unless | |
vars: | |
"file" string => "/full/path/to/file.json"; | |
classname:: #always gate file reads as tightly as possible | |
"data" data => readjson("$(file)", inf), | |
if => fileexists("$(file)"), #don't try to read if file is missing | |
unless => isvariable("$(this.promiser)"); #don't read file more than once | |
#you can't do all that in pre 3.7 but you can do some | |
# sometimes I prefer an error if the file is missing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#it can be non-intuitive to get a slist from a json data object in CFEngine | |
# this can be useful if you have a json with hostnames as keys | |
vars: | |
"data" data => parsejson("{ "key": ["one", "two", "three"] }"); | |
"values" slist => getvalues("data[key]"); #just pass the name, not the variable itself | |
#just an example, I haven't loaded moredata in this gist | |
"info" slist => getvalues("moredata[$(sys.fqhost)]"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#this code has not been tested for minor bugs, but the idea is solid | |
vars: | |
"sync_data" data => parsejson('{ "dir1":"class1", "dir2":"class2" }'); | |
"dirs" slist => getindices("sync_data"); | |
files: | |
"$(dirs)" | |
create => "true", | |
copy_from => secure_cp("/base/$(dirs)", "$(sys.policy_hub)"), | |
if => "$(sync_data[dirs])"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
description "BitTorrent Sync" | |
start on filesystem | |
stop on shutdown | |
respawn | |
expect fork | |
script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pseudocode | |
if x == 7 and (y<10 or y>20): | |
do something | |
#using classes | |
or_class_set or => {"less_than_ten", "greater_than_twenty"}; | |
and_class_set and => {"or_class_set", "equals_seven"}; | |
#is the same as | |
and_class_set and => {"equals_seven", "less_than_ten|greater_than_twenty"}; |