From c56a644fb3a9acc0687746f3dfd34be0dc1408d9 Mon Sep 17 00:00:00 2001 From: sirkubax Date: Fri, 27 Oct 2017 14:55:16 +0200 Subject: [PATCH] copy into docker --- .ansible.html.markdown.swl | Bin 36864 -> 36864 bytes ansible.html.markdown | 55 +++++++++++++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/.ansible.html.markdown.swl b/.ansible.html.markdown.swl index 94a17a7deba496b8b32e79fdb7f1526ddfb3df1d..4664ca7078a38128e7de3801f3fb19533d3b9b7b 100644 GIT binary patch delta 1636 zcmbW2O^6&t7=~-ZvPn!9HpwLc!OyIctj^CK6mcYCP>_uo&}1>h9JXt!YkJD*?i#zQ zccv3U=cXu#VTk8|-X*N&plA@(n_dn6fPzOc2M+;7@U7~Z&5no%3!b66tLpoGtLMt~ zU01H}qR#5eYi)X>@fgEcVl1!ye*Vcr2U)GbSU>OZt2Z9H@!bBUIWc}|>4CW;TdysR zn~Sf{GuB+F4v6uAXU63>`x*Nh+yWXL27m5j>@K(lu7Y>K8{i_?1OmJQ9tRJCJzzKZ z^*+Xa0-u9V!Mos1&;t>;02aU>dl|b8KH1Ak_Aw?m!TaDn@Z%oFegNNt@4zka8Aw3_ z1b7(S-3=q)Tks+H0F1y8^ueRx5cmt}{sO)PUx1t7Bd`jZ3tMyZZ_khKf8kn581;Ir z5@o5UjZJwXTT!O-0WF_uvz^OECvszu$*vkbGPB^fyMr@tlVW3P(7!*ga}qoy_;SuL zlOtJ*+$x=t?oy%ij4U^OLsnA=H>nJLOorGp2Ay7Ox7XI$#Ea>xLEZAmc&i;rxxs!M zl_L@7p(IY7Sc|^1Ep%7~=g+S9WQJv6%7GM$$M74O7V&t<3o~`#ZR6);jkLv)4a{qe zMq?%$EcleRGnypSDG-lJBbwdKBZTFWtWl<8N#${#hNLWVcA2l#NTojd8c8dhGoShT z$>+~9<|=47B-!mMp=2rwLKwEE3>lRS;I5me!quC{ z$`%Z^$3b$qbXRHGovQ9AnA<<1SVv0GP}v?DW>g0@T)?MP`YPYHW*XFnbljl?y@b2m z@JPDC2Se1S71SydPC>NEGsT^ubQd?Cxk;W(OoKPlho~2%Pt_sIQ zPeO>$3Yh{?Cy?xb3-sU^npYaq{mKJOV@$&RKLPm=?}fiJ5auicKYXf_Ov|bq^dEWt z!|Wu$X%AZW95Qd+^kf{jDC|G~%+puFT+f672m}}y)@pu^WE2)+(9vUH$SzGvoVZbCqYIA!qyFST z0eMEL&4mJ!^?9AS7#O6vAsX~23pz~JyU)YG&=15GKr9W!;y}C=sA3}!Zvf&&K)eu$ zWq??kdov@87uRG1x2cnb!UHBh^nS>x5R{spSzMA@H2Gb4@Mb&TV?w;QfJVgeLM)Nm JEST_K9{`_EDIfp< diff --git a/ansible.html.markdown b/ansible.html.markdown index 53ea153f..ae5ca01e 100644 --- a/ansible.html.markdown +++ b/ansible.html.markdown @@ -249,7 +249,9 @@ ansible -m shell -a 'echo "{{ my_variable }}"' -e 'my_variable="{{ lookup("pipe" ``` -### Register +### Register and Conditional + +#### Register Another way to dynamicaly generate the variable content is a `register` command `Register` is also useful to store an output of a task, and use it's value as a logic for execution further tasks. @@ -257,6 +259,56 @@ for execution further tasks. (venv) user@host:~/ansible-for-learnXinYminutes$ ansible-playbook playbooks/register_and_when.yml ``` +```yaml +#file content +--- +- hosts: localhost + tasks: + - name: check the system capacity + shell: df -h / + register: root_size + + - name: debug root_size + debug: + msg: "{{ root_size }}" + + - name: debug root_size return code + debug: + msg: "{{ root_size.rc }}" + + + - name: Print this message when return code of 'check the system capacity' was ok + debug: + msg: "{{ root_size.rc }}" + when: root_size.rc == 0 + +``` +#### Conditionals + +You can define complex logic with ansible and Jinja functions. Most common is usage of `when:`, with some variable (often dynamicly generated in previous playbook steps with `register` or `lookup`) + + + +### ansible - tags, limmit + +You should know about a way to increase efficiency by this simple functionality + +#### TAGS + You can tag a task, role (and its tasks), include, etc... + You can then limit an execution by using + --tags tagA, other_tag,... + + There are special tags: always + + --skip-tags can be used to exclude a block of code + +#### LIMMIT + You can limmit an execution of your tasks to defined hosts + --limit my_hostname + --limit groupname + --limit some_prefix* + --limit hostname:group #JM + ### Templates Template is a powerfull way to deliver some (partially) dynamic content. Ansible uses **Jinja2** langueage to describe the template. @@ -286,7 +338,6 @@ Junja is powerfull. It has built-in many usefull functions. # if variable is undefined - use default value {{ some_variable | default('default_value') }} ``` -### ansible - tags, limmit, diff, check_mode ### ansible-vault To maintain **ifrastructure as a code** you need to store secrets.