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?
ls /var/cfengine/inputs ls /var/cfengine/masterfiles
Jak udělat změnu
Příprava gitu
apt-get install git git config -l git config --global user.name "Tvoje Jmeno" git config --global user.email tvuj_login@civ.zcu.cz
Klon
cd /root git clone file:///afs/zcu.cz/project/software/git/cfengine.git cf cd cf git checkout production git branch --set-upstream production origin/production
Změna v gitu a propagace
cd /root/cf git checkout -b zmena git branch vim file.cf cf-promises -cf ./promises.cf cf-agent -KnIf ./promises.cf git status git commit file.cf git checkout master git merge zmena git push git checkout production git merge zmena git push