LPS:CFEngine3/hands-on
Z HelpDesk
Instalace
echo "deb http://cfengine.com/pub/apt stable main" >> /etc/apt/sources.list echo "deb http://download.zcu.cz/public/software/linux/debian stable main" >> /etc/apt/sources.list
apt-get update apt-get install cfengine-community vim-syntax-cfengine3
Ukázkové bundly
Spousta příkladů:
/var/cfengine/share/doc/examples/
Hello world: test1.cf
body common control { bundlesequence => {"main"}; } bundle agent main { reports: verbose:: "Hello World"; }
cf-agent -Kf ./test1.cf cf-agent -Kf ./test1.cf -D verbose 2014-03-18T17:11:18+0100 notice: R: Hello World
Soubor: test2.cf
body common control { bundlesequence => { "main" }; } bundle agent main { vars: any:: "file" string => "/tmp/cftest.txt"; classes: any:: "file_exists" expression => fileexists("$(file)"); files: any:: "/tmp/cftest.txt" create => "true", classes => if_repaired("file_created"); reports: file_exists:: "Soubor existuje"; file_created:: "Soubor byl vytvoren"; }
cf-promises -cf ./test2.cf ./test2.cf:20:0: error: Undefined body if_repaired with type classes
Ukradneme z /var/cfengine/share/CoreBase/lib/3.5/common.cf
body classes if_repaired(x) { promise_repaired => { "$(x)" }; }
cf-promises -cf ./test2.cf cf-agent -KInf ./test2.cf cf-agent -KInf ./test2.cf
Úkoly
- nastavit opravneni souboru
Implicitní cyklus: test3.cf
body common control{ bundlesequence => { "example" }; } bundle agent example { vars: any:: "v[index_1]" string => "value_1"; "v[index_2]" string => "value_2"; "x" slist => getindices("v"); "y" slist => getvalues("v"); reports: any:: "All indices:"; " Found index: $(x) with value \"$(v[$(x)])\""; "All values:"; " Found value: $(y)"; "Kombinace $(x) $(y)"; }
První kontakt
cf-agent --bootstrap cf.civ.zcu.cz
Co jsme získali?
cd /var/cfengine/ ls inputs ls masterfiles