-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathansible.tex
388 lines (349 loc) · 10.7 KB
/
ansible.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
\PassOptionsToPackage{dvipsnames}{xcolor}
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
%\usepackage{verbatim}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{array}
\usepackage{tikz}
\usetikzlibrary{arrows,calc,intersections,through,decorations.pathmorphing,backgrounds,positioning,fit}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{fancyvrb}
\usepackage{listings}
\usepackage{minted}
\usepackage{ulem}
\usepackage{hyperref}
\usetheme{Madrid}
\AtBeginSection[]
{
\begin{frame}<beamer>
\frametitle{Syllabus}
{\scriptsize\tableofcontents[currentsection,hideothersubsections]
}
\end{frame}
}
\fvset{commandchars=\\\{\}}
\title{Ansible \textit{set\_fact} \& \textit{add\_host}}
\author{Julien Girardin}
\date{\today}
\titlegraphic{
\includegraphics[width=0.06\textwidth]{images/ansible_badge.png}
\hspace{0.1cm}
\includegraphics[width=0.3\textwidth]{images/ansible.png}
}
\begin{document}
\maketitle{}
\begin{frame}
\begin{exampleblock}{Versions disclaimer}
Should work on ansible >= 1.9
(Special mentions for ansible 2.0 only)
\end{exampleblock}
\end{frame}
\section{Server scope variable}
\begin{frame}[fragile]
\frametitle{Example}
\begin{exampleblock}{Example featuring \textit{set\_fact}}
\begin{minted}{yaml}
- name: "A task with set_fact"
set_fact: ga=foo
args:
bu: bar
zo: baz|bool
meu: >- # add "-" to strip the \n at the end
{{ complex_computation_in_jinja|list }}
\end{minted}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\begin{columns}
\column{0.4\textwidth}
\begin{block}{site\_1.yml}
\footnotesize{
\inputminted[firstline=1, lastline=2]
{yaml}{sources/site_1.yml}
\inputminted[firstline=3, lastline=3,
frame=single,
framesep=0pt]
{yaml}{sources/site_1.yml}
\inputminted[firstline=4, lastline=10]
{yaml}{sources/site_1.yml}
\inputminted[firstline=11, lastline=11,
frame=single,
framesep=0pt]
{yaml}{sources/site_1.yml}
}
\end{block}
\column{0.55\textwidth}
\vbox to .7\textheight{
\footnotesize{
\inputminted[firstline=58, lastline=60,
breaklines,
frame=single,
framesep=0pt]
{yaml}{sources/roles/graphite/tasks/main.yml}
\vfill
\inputminted[firstline=1, lastline=5,
breaklines,
frame=single,
framesep=0pt]
{yaml}{sources/roles/ferm_basic/tasks/main.yml}
}
}
\end{columns}
\end{frame}
\begin{frame}[fragile]
\begin{columns}
\column{0.4\textwidth}
\begin{alertblock}{site\_2.yml}
\footnotesize{
\inputminted{yaml}{sources/site_2.yml}
}
\end{alertblock}
\column{0.55\textwidth}
\scriptsize{
\begin{Verbatim}[label={Ansible output 1}]
TASK [graphite | Expose graphite ports] *******
\textcolor{Green}{ok: [graphite]}
\textcolor{Green}{ok: [shinken]}
TASK [ferm_basic | Open tcp port in firewall] *
\textcolor{Orange}{changed: [graphite]}
\textcolor{Orange}{changed: [shinken]}
TASK [shinken | Export Shinken web UI ports] **
\textcolor{Green}{ok: [graphite]}
\textcolor{Green}{ok: [shinken]}
TASK [ferm_basic | Open tcp port in firewall] *
\textcolor{Orange}{changed: [graphite]}
\textcolor{Orange}{changed: [shinken]}
\end{Verbatim}
}
\end{columns}
\vfill
\begin{center}
\visible<2->{
$\Rightarrow$ First: remove the shinken ports. Then: add it again.
}
\end{center}
\end{frame}
\begin{frame}[fragile]
\begin{columns}
\column{0.4\textwidth}
\begin{block}{site\_3.yml}
\footnotesize{
\inputminted[firstline=1, lastline=2]
{yaml}{sources/site_3.yml}
\inputminted[firstline=3, lastline=3,
frame=single,
framesep=0pt]
{yaml}{sources/site_3.yml}
\inputminted[firstline=4, lastline=6]
{yaml}{sources/site_3.yml}
\inputminted[firstline=7, lastline=7,
frame=single,
framesep=0pt]
{yaml}{sources/site_3.yml}
\inputminted[firstline=8]
{yaml}{sources/site_3.yml}
}
\end{block}
\column{0.55\textwidth}
\vbox to .7\textheight{
\scriptsize{
\inputminted[firstline=64, lastline=70,
breaklines,
frame=single,
framesep=0pt]
{yaml}{sources/roles/graphite/tasks/main.yml}
\vfill
\inputminted[firstline=1, lastline=9,
breaklines,
frame=single,
framesep=0pt]
{yaml}{sources/roles/ferm_full/tasks/ports_dict.yml}
}
}
\end{columns}
\end{frame}
\begin{frame}[fragile]
\begin{columns}
\column{0.4\textwidth}
\begin{block}{site\_4.yml}
\footnotesize{
\inputminted[firstline=1, lastline=6]
{yaml}{sources/site_4.yml}
\inputminted[firstline=7, lastline=8,
frame=single,
framesep=0pt]
{yaml}{sources/site_4.yml}
\inputminted[firstline=9]
{yaml}{sources/site_4.yml}
}
\end{block}
\column{0.55\textwidth}
\vbox to .9\textheight{
\scriptsize{
\inputminted[firstline=13,
breaklines,
frame=single,
framesep=0pt]
{yaml}{sources/roles/ferm_full/tasks/ports_dict.yml}
\vfill
\textit{cleanup\_input.yml:}
\inputminted[breaklines,
frame=single,
framesep=0pt]
{yaml}{sources/roles/ferm_full/tasks/cleanup_input.yml}
}
}
\end{columns}
\end{frame}
\begin{frame}[fragile]
\begin{alertblock}{Warning}
A missing tag \textit{ferm} or \textit{firewall}
may un-expose a port and remove it from firewall
\end{alertblock}
\end{frame}
\section{Global scope variable}
%\subsection{Read vars from other servers}
\begin{frame}[fragile]
\frametitle{Example}
\begin{exampleblock}{The classical but usefull \textit{hostvars}}
\footnotesize{
\begin{minted}[breaklines]{yaml}
- hosts: master
tasks:
- name: "Get content from master"
slurp:
path: /root/.ssh/id_rsa.pub
register: sshkey
delegate_to: "{{ groups.master[0] }}"
run_once: True
- hosts: slaves
tasks:
- name: "Add sshpub key from the master"
authorized_keys:
key: "{{ hostvars[groups.master[0]].sshkey.content|b64decode }}"
user: root
\end{minted}
}
\end{exampleblock}
\end{frame}
%\subsection{add\_host}
\begin{frame}[fragile]
\begin{block}{Global vars}
How to pass a variable globally ?
(ie: whatever the server who set the var and whatever the server who read the var)
\end{block}
\visible<2->{
\begin{center}
$\Rightarrow$ \textbf{\textit{Groups}}
\end{center}
}
\end{frame}
\begin{frame}[fragile]
\frametitle{Example}
\begin{exampleblock}{Example featuring \textit{add\_host}}
\begin{minted}{yaml}
- name: "Example with add_hosts"
add_host:
name: "{{ groups.slaves[0] }}"
groups: leader
foo: bar
\end{minted}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{Common pitfall}
\textit{add\_host} litteraly breaks the parallelism of ansible.
It seems to have: \fbox{\lstinline{run_once: True}} always enabled.
\begin{columns}
\column{0.5\textwidth}
\begin{alertblock}{Doesn't work as expected}
\footnotesize{
\begin{minted}{yaml}
- name: "Add hosts to shinken"
add_host:
name: "{{ inventory_hostname }}"
groups: shinken
\end{minted}
}
\end{alertblock}
\column{0.45\textwidth}
% \visible<2->{
\begin{minipage}{\textwidth}
\begin{exampleblock}{Thing you might want}
\footnotesize{
\begin{minted}{yaml}
- name: "Add hosts to shinken"
add_host:
name: "{{ item }}"
groups: shinken
with_items: "{{ play_hosts }}"
\end{minted}
}
\end{exampleblock}
\end{minipage}
% }
\end{columns}
\end{frame}
\begin{frame}
\begin{columns}
\column{0.45\textwidth}
\begin{block}{site\_5.yml}
\footnotesize{
\inputminted[firstline=1, lastline=2]
{yaml}{sources/site_5.yml}
\inputminted[firstline=3, lastline=3,
frame=single,
framesep=0pt]
{yaml}{sources/site_5.yml}
\inputminted[firstline=4, lastline=7]
{yaml}{sources/site_5.yml}
\inputminted[firstline=8, lastline=8,
frame=single,
framesep=0pt]
{yaml}{sources/site_5.yml}
\inputminted[firstline=9]
{yaml}{sources/site_5.yml}
}
\end{block}
\column{0.5\textwidth}
\vbox to .7\textheight{
\scriptsize{
\inputminted[firstline=74, lastline=79,
breaklines,
frame=single,
framesep=0pt]
{yaml}{sources/roles/graphite/tasks/main.yml}
\vfill
\textit{\tiny{
shinken\_graphite/templates/graphite\_module.cfg.j2}}
\inputminted[breaklines,
frame=single,
framesep=0pt]
{yaml}{sources/roles/shinken_graphite/templates/graphite_module.cfg.j2}
}
}
\end{columns}
\end{frame}
\section{Fun facts (short)}
\begin{frame}[fragile]
\frametitle{Set var on another host}
\begin{block}{Since ansible $\sim$ 1.9}
\begin{minted}{yaml}
- name:
add_host:
name: "another.server"
group: all
foo: bar
\end{minted}
\end{block}
\end{frame}
\begin{frame}[fragile]
\frametitle{Variable pointer}
\begin{block}{Since ansible 2.0}
\inputminted[firstline=1]{yaml}{sources/variable_name.yml}
\end{block}
\end{frame}
\end{document}