--
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-cfengine+unsubscribe@googlegroups.com.
To post to this group, send email to help-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/help-cfengine.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to help-cfengin...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to help-cfengine+unsubscribe@googlegroups.com.
bundle agent test
{
vars:
any::
"dot_ssh" string => "/tmp";
"pubkeys_dir" string => "$(dot_ssh)/masterfiles-3.10.0/masterfiles/controls";
"pubkeys_list" slist => findfiles( "$(pubkeys_dir)/*.cf" );
reports:
"$(pubkeys_list)";
}
beto@corsair [inputs]$ cf-agent -V
CFEngine Core 3.9.2
beto@corsair [inputs]$ cf-agent -KIf ./findfiles.cf
R: /tmp/masterfiles-3.10.0/masterfiles/controls/cf_agent.cf
R: /tmp/masterfiles-3.10.0/masterfiles/controls/cf_execd.cf
R: /tmp/masterfiles-3.10.0/masterfiles/controls/cf_hub.cf
R: /tmp/masterfiles-3.10.0/masterfiles/controls/cf_monitord.cf
R: /tmp/masterfiles-3.10.0/masterfiles/controls/cf_runagent.cf
R: /tmp/masterfiles-3.10.0/masterfiles/controls/cf_serverd.cf
R: /tmp/masterfiles-3.10.0/masterfiles/controls/def.cf
R: /tmp/masterfiles-3.10.0/masterfiles/controls/def_inputs.cf
R: /tmp/masterfiles-3.10.0/masterfiles/controls/reports.cf
R: /tmp/masterfiles-3.10.0/masterfiles/controls/update_def.cf
R: /tmp/masterfiles-3.10.0/masterfiles/controls/update_def_inputs.cf
For what it's worth, I don't get your result. Any chance there's some other config that's producing the extra output?
~ ❯❯❯ cat foo.cf
body common control
{
bundlesequence => { foo };
}
bundle agent foo
{
vars:
"dot_ssh" string => "/tmp/foodir";
"pubkeys_dir" string => "$(dot_ssh)/pubkeys";
"pubkeys_list" slist => findfiles("$(pubkeys_dir)/*");
reports:
"$(pubkeys_list)";
}
~ ❯❯❯ ls /tmp/foodir/pubkeys
file1 file2 file3 file4 file5
~ ❯❯❯ cf-agent -f ./foo.cf
R: /tmp/foodir/pubkeys/file1
R: /tmp/foodir/pubkeys/file2
R: /tmp/foodir/pubkeys/file3
R: /tmp/foodir/pubkeys/file4
R: /tmp/foodir/pubkeys/file5
~ ❯❯❯
On 9 Mar 2017, at 12:35, Todd Erwin wrote:
Yes and what i have is working, minus the fact that the SLIST contains the VARNAME which causes errors in every run because of nofile exsisting. Also I have a central repository for keys that get's copied locally to each box so hardcoding the slist is not an option. The code that Im using is actually documented with some slight modifications..
--
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-cfengine+unsubscribe@googlegroups.com.
Hey Todd,
I was just skimming the thread and thought you might find this example
interesting.
If I understand correctly you have some data (public keys) that you want to
ensure exist in a file. These should be the ONLY entries in the file, but you
don't want to re-write the file each time the agent runs.
I really like to use a collection pattern.
bundle agent main { vars: "string1" string => "key1", meta => { "mytag" }; "string2" string => "key2", meta => { "mytag" }; "collected" data => variablesmatching_as_data(".*", "mytag"); "i" slist => sort( getvalues(collected), lex); reports: "$(i)"; }
R: key1 R: key2
In the above policy you have 2 strings (string1
and string2
). Their values
could be populated by reading in data from each of your individual files. We tag
them with mytag
so that we can easily find them. This allows you to have more
data sources outside this bundle that might be contributing to your full data
set.
We collect all the variables tagged with mytag
into a data structure and then
extract the values into a sorted list. The sort would be important so that the
order of the list doesn't change and cause unnecessary writes.
From there you could use a template (I recommend mustache templates) or an
edit_line
promise to ensure that only that canonical list of content exists in
the file.
You could also use a classic array as a generator like this:
/tmp/iterate-top.mustache
:
{{#-top-}} {{.}} {{/-top-}}
Policy:
bundle agent main { vars: "keys" slist => lsdir("/etc/ssh/", ".*.pub", "false"); "key[$(keys)]" string => readfile( "/etc/ssh/$(keys)", inf); "i" slist => sort( getvalues(key), lex); files: "/tmp/example.txt" create => "true", edit_template => "/tmp/iterate-top.mustache", template_method => "mustache", template_data => @(i); #TIL template_data can take lists just like data. reports: "$(key$(range))"; "$(range)"; "/tmp/example.txt:" printfile => cat("/tmp/example.txt"); }
R: /tmp/example.txt: R: ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBB7BkQAUSfVHfbsswmCcK43ES3rvprk+s33c4XTslhWOdlEzUf/zfQpHX/psjFswkyQSil9TtI7rXfqGhYcsQGU= root@nickanderson-ThinkPad-W550s R: ssh-dss AAAAB3NzaC1kc3MAAACBAObSHMPdeRlXA7Qlzpdlsxg1Sdgts3U+o3a4o0vK/ta0iYJGWWyvw/5Yq8iWwDlRTb4T12zZ0P71tAmZgGrjQnkQCv+aFr6KBjJAqxOUTDfogAB3tacKL23zXgFzj5Rs5h11UHQTggmDUKHBm98CV4/1cpeuPMSP/i+o0qhrJtJ1AAAAFQD+I4hCTCbaUTi93TM1zox9KiuVGwAAAIEAlNhUEqEUHoh0S3iOyJqA+ULM4Y6PHUIPlBzYrIWXdDzi8EQJ2fKssDerfRw4GWldc1ZZvEkKK0iaDGPuWEDlZAP09YMb82kbXlDqIsgH79sH4JVSj1ew0H+aJvoizEjszRxLy77lT7VF8UgI8l8vhUuqNYJ0rMEZWUSO7PcNlKoAAACBALphnIeqVB44tHyNmflZZURCnGgNAQj3qEQkCILynZEYc9fr8f4Hqso3p2qJBGV2nWp8ADx89+C83iKw11wyujN73fow3JpMkzO7pwSP7/az6i/DCeSG4CxQTHJdt8c9uEk0rX7bPhQONHHK3Aap3T7wlysecNa/2IiJFGs1CpX/ root@nickanderson-ThinkPad-W550s R: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJlAr3MIXec9zlwSicQPTdWwiwNSAgt/a9he5nMFlX2P root@nickanderson-ThinkPad-W550s R: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDIWriCUQAisvcsq+51/pCV8aHrihMbfpmVNff/M4hZwS8dChGPQbmvhtfxL/LcX3iNVoD1mH6lRKCeQJjjY2u9n6EhMgx6yW6l0oIlnGuJ0qYArBB6zoCCfapK/9HcoQRbso/QFDwMc4hqNFxot6iBkxUd1ib6eKIEUBt8FJRMAQNXCfVQ/IrQ3q0Ksx2NVNpdrWo57eUGIu6qrGFUsYZCH+MRCdhvjSB7A8kPH7X/pgNAUcIkIza5omarz3hWRckTL+62Wz83mzqLIOsC/xB9Ir0BEKBwb/95b6XKzOgXByOtutEzCOmZxEedcT7SoA4JQfBjloHpKyCftiTcjG8H root@nickanderson-ThinkPad-W550s
You could even mix them and merge the results together with mergedata.
–
Nick Anderson
Doer of things, CFEngine