-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1500 lines (792 loc) · 104 KB
/
index.html
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.0.0">
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.4.1">
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=7.4.1">
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=7.4.1">
<link rel="mask-icon" href="/images/logo.svg?v=7.4.1" color="#222">
<link rel="alternate" href="/atom.xml" title="Anna X" type="application/atom+xml">
<link rel="stylesheet" href="/css/main.css?v=7.4.1">
<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.7.0">
<script id="hexo-configurations">
var NexT = window.NexT || {};
var CONFIG = {
root: '/',
scheme: 'Pisces',
version: '7.4.1',
exturl: false,
sidebar: {"position":"left","display":"post","offset":12,"onmobile":false},
copycode: {"enable":false,"show_result":false,"style":null},
back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
bookmark: {"enable":false,"color":"#222","save":"auto"},
fancybox: false,
mediumzoom: false,
lazyload: false,
pangu: false,
algolia: {
appID: '',
apiKey: '',
indexName: '',
hits: {"per_page":10},
labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
},
localsearch: {"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
path: 'search.xml',
motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
translation: {
copy_button: 'Copy',
copy_success: 'Copied',
copy_failure: 'Copy failed'
},
sidebarPadding: 40
};
</script>
<meta name="description" content="Happy coding ...">
<meta property="og:type" content="website">
<meta property="og:title" content="Anna X">
<meta property="og:url" content="https://vmnet8.github.io/index.html">
<meta property="og:site_name" content="Anna X">
<meta property="og:description" content="Happy coding ...">
<meta property="og:locale" content="en">
<meta name="twitter:card" content="summary">
<link rel="canonical" href="https://vmnet8.github.io/">
<script id="page-configurations">
// https://hexo.io/docs/variables.html
CONFIG.page = {
sidebar: "",
isHome: true,
isPost: false,
isPage: false,
isArchive: false
};
</script>
<title>Anna X</title>
<noscript>
<style>
.use-motion .brand,
.use-motion .menu-item,
.sidebar-inner,
.use-motion .post-block,
.use-motion .pagination,
.use-motion .comments,
.use-motion .post-header,
.use-motion .post-body,
.use-motion .collection-header { opacity: initial; }
.use-motion .logo,
.use-motion .site-title,
.use-motion .site-subtitle {
opacity: initial;
top: initial;
}
.use-motion .logo-line-before i { left: initial; }
.use-motion .logo-line-after i { right: initial; }
</style>
</noscript>
</head>
<body itemscope itemtype="http://schema.org/WebPage">
<div class="container use-motion">
<div class="headband"></div>
<header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
<div class="header-inner"><div class="site-brand-container">
<div class="site-meta">
<div>
<a href="/" class="brand" rel="start">
<span class="logo-line-before"><i></i></span>
<span class="site-title">Anna X</span>
<span class="logo-line-after"><i></i></span>
</a>
</div>
<p class="site-subtitle">Anna's Tech Blog</p>
</div>
<div class="site-nav-toggle">
<div class="toggle" aria-label="Toggle navigation bar">
<span class="toggle-line toggle-line-first"></span>
<span class="toggle-line toggle-line-middle"></span>
<span class="toggle-line toggle-line-last"></span>
</div>
</div>
</div>
<nav class="site-nav">
<ul id="menu" class="menu">
<li class="menu-item menu-item-home">
<a href="/" rel="section"><i class="fa fa-fw fa-home"></i>Home</a>
</li>
<li class="menu-item menu-item-about">
<a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>About</a>
</li>
<li class="menu-item menu-item-tags">
<a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>Tags<span class="badge">19</span></a>
</li>
<li class="menu-item menu-item-archives">
<a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>Archives<span class="badge">51</span></a>
</li>
<li class="menu-item menu-item-search">
<a href="javascript:;" target="_blank" rel="noopener" class="popup-trigger">
<i class="fa fa-search fa-fw"></i>Search</a>
</li>
</ul>
</nav>
<div class="site-search">
<div class="popup search-popup">
<div class="search-header">
<span class="search-icon">
<i class="fa fa-search"></i>
</span>
<div class="search-input-container">
<input autocomplete="off" autocorrect="off" autocapitalize="none"
placeholder="Searching..." spellcheck="false"
type="text" id="search-input">
</div>
<span class="popup-btn-close">
<i class="fa fa-times-circle"></i>
</span>
</div>
<div id="search-result"></div>
</div>
<div class="search-pop-overlay"></div>
</div>
</div>
</header>
<div class="back-to-top">
<i class="fa fa-arrow-up"></i>
<span>0%</span>
</div>
<main id="main" class="main">
<div class="main-inner">
<div class="content-wrap">
<div id="content" class="content">
<div class="posts-expand">
<article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="en">
<link itemprop="mainEntityOfPage" href="https://vmnet8.github.io/2020/06/21/Ansible-part12-block-rescure-and-always/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="Anna X">
<meta itemprop="description" content="Happy coding ...">
<meta itemprop="image" content="https://avatars0.githubusercontent.com/u/34552097">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="Anna X">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a href="/2020/06/21/Ansible-part12-block-rescure-and-always/" class="post-title-link" itemprop="url">Ansible-part12: block rescue and always</a>
</h1>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-06-21 19:50:29 / Modified: 22:11:42" itemprop="dateCreated datePublished" datetime="2020-06-21T19:50:29-07:00">2020-06-21</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-comment-o"></i>
</span>
<span class="post-meta-item-text">Disqus: </span>
<a title="disqus" href="/2020/06/21/Ansible-part12-block-rescure-and-always/#comments" itemprop="discussionUrl"><span class="post-comments-count disqus-comment-count" data-disqus-identifier="2020/06/21/Ansible-part12-block-rescure-and-always/" itemprop="commentCount"></span></a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h4 id="Blocks"><a href="#Blocks" class="headerlink" title="Blocks"></a>Blocks</h4><p>Blocks allow for logical grouping of tasks and in play error handling.</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">- name: test blocks resuce and always</span><br><span class="line"> hosts: web2</span><br><span class="line"> tasks:</span><br><span class="line"> - name: first command</span><br><span class="line"> debug: </span><br><span class="line"> msg: "first message success"</span><br><span class="line"> - name: second command</span><br><span class="line"> command: /bin/false</span><br><span class="line"> - name: third command</span><br><span class="line"> debug:</span><br><span class="line"> msg: "this is third command"</span><br></pre></td></tr></table></figure>
<p>There are three tasks in this playbook, but the second one is a wrong command, which will failed to be executed.</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">anna@ansible-controller:~/Desktop/ansible-code/inventory/block-resuce-always$ ansible-playbook -i hosts site.yml </span><br><span class="line"></span><br><span class="line">PLAY [test blocks resuce and always] ******************************************************************************************************************************************************************************************************************</span><br><span class="line"></span><br><span class="line">TASK [Gathering Facts] ********************************************************************************************************************************************************************************************************************************</span><br><span class="line">ok: [cube4200]</span><br><span class="line"></span><br><span class="line">TASK [first command] **********************************************************************************************************************************************************************************************************************************</span><br><span class="line">ok: [cube4200] => {</span><br><span class="line"> "msg": "first message sucess"</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">TASK [second command] *********************************************************************************************************************************************************************************************************************************</span><br><span class="line">fatal: [cube4200]: FAILED! => {"changed": true, "cmd": ["/bin/false"], "delta": "0:00:00.011635", "end": "2020-06-21 21:31:18.222247", "msg": "non-zero return code", "rc": 1, "start": "2020-06-21 21:31:18.210612", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}</span><br><span class="line"></span><br><span class="line">PLAY RECAP ********************************************************************************************************************************************************************************************************************************************</span><br><span class="line">cube4200 : ok=2 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0</span><br></pre></td></tr></table></figure>
<p>Since the second faild, so the third one will be skipped. I don’t want this happen, So I use block to solove this.</p>
<h4 id="Blocks-error-handling"><a href="#Blocks-error-handling" class="headerlink" title="Blocks error handling"></a>Blocks error handling</h4><p>Blocks also introduce the ability to handle errors in a way similar to exceptions in most programming languages. Blocks only deal with ‘failed’ status of a task. A bad task definition or an unreachable host are not ‘rescuable’ errors.</p>
<p>three key words: block rescure always are similar as try exception and final in python.<br>block section: will execute normally<br>rescue section: will execute only when block section has error<br>always section: will run no matter what the task status is.</p>
<p>I add block into playbook</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">- name: test blocks recue and always</span><br><span class="line"> hosts: web2</span><br><span class="line"> tasks:</span><br><span class="line"> - block:</span><br><span class="line"> - name: test block, this is first command</span><br><span class="line"> debug: </span><br><span class="line"> msg: "first message success"</span><br><span class="line"> - name: second command</span><br><span class="line"> command: /bin/false</span><br><span class="line"> rescue:</span><br><span class="line"> - name: third command, this is excuted only when block failed, otherwise will be skipped</span><br><span class="line"> debug:</span><br><span class="line"> msg: "some command in block failed, so this message be excuted"</span><br></pre></td></tr></table></figure>
<p>after running</p>
<!--noindex-->
<div class="post-button">
<a class="btn" href="/2020/06/21/Ansible-part12-block-rescure-and-always/#more" rel="contents">
Read more »
</a>
</div>
<!--/noindex-->
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="en">
<link itemprop="mainEntityOfPage" href="https://vmnet8.github.io/2020/06/19/Ansible-part11-cron-module-to-power-off-remote-wake-on-lab-module-to-power-on-remote/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="Anna X">
<meta itemprop="description" content="Happy coding ...">
<meta itemprop="image" content="https://avatars0.githubusercontent.com/u/34552097">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="Anna X">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a href="/2020/06/19/Ansible-part11-cron-module-to-power-off-remote-wake-on-lab-module-to-power-on-remote/" class="post-title-link" itemprop="url">Ansible part11: cron module to power off remote, Wake-on-LAN module to power on remote</a>
</h1>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-06-19 00:01:43 / Modified: 01:09:23" itemprop="dateCreated datePublished" datetime="2020-06-19T00:01:43-07:00">2020-06-19</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-comment-o"></i>
</span>
<span class="post-meta-item-text">Disqus: </span>
<a title="disqus" href="/2020/06/19/Ansible-part11-cron-module-to-power-off-remote-wake-on-lab-module-to-power-on-remote/#comments" itemprop="discussionUrl"><span class="post-comments-count disqus-comment-count" data-disqus-identifier="2020/06/19/Ansible-part11-cron-module-to-power-off-remote-wake-on-lab-module-to-power-on-remote/" itemprop="commentCount"></span></a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h4 id="power-off-using-cron"><a href="#power-off-using-cron" class="headerlink" title="power off using cron"></a>power off using cron</h4><p>I am going to power off one of my node using cron module.</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">- name: cron to poweroff</span><br><span class="line"> hosts: web2</span><br><span class="line"> become: yes</span><br><span class="line"></span><br><span class="line"> tasks:</span><br><span class="line"> - name: power off</span><br><span class="line"> cron:</span><br><span class="line"> name: "shutdown"</span><br><span class="line"> user: root</span><br><span class="line"> minute: "52"</span><br><span class="line"> hour: "16"</span><br><span class="line"> job: "sync; /sbin/shutdown"</span><br></pre></td></tr></table></figure>
<p>after running playbook, the remote will be shutdown on 16:42 everyday.</p>
<h4 id="Wake-on-LAN"><a href="#Wake-on-LAN" class="headerlink" title="Wake-on-LAN"></a>Wake-on-LAN</h4><p>Compare to shutdown, power on remote is a little bit hard. Ansible has a Wake-on-LAN module can do it, but remote needs has Wake-on-LAN option is enabled.<br>Wake-on-LAN (WOL) is an Ethernet networking standard that allows a server to be turned on by a network message.</p>
<p>If you don’t see this option in your BIOS or UEFI, check the computer or motherboard’s manual to see if it supports Wake-on-LAN.</p>
<p>To verify if remote supports Wake-on-LAN, use <code>ethtool -s eth0 wol g</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[anna@cube4200 ~]$ sudo ethtool enp3s0 |grep Wake</span><br><span class="line"> Supports Wake-on: pumbg</span><br><span class="line"> Wake-on: g</span><br></pre></td></tr></table></figure>
<p>It shows remote node cube4200 supports Wake-on-LAN</p>
<p>Let’s write playbook</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">- name: power on</span><br><span class="line"> hosts: web2</span><br><span class="line"> gather_facts: no</span><br><span class="line"></span><br><span class="line"> tasks:</span><br><span class="line"> - name: Send a magic Wake-on-LAN packet to turn on individual systems via gateway</span><br><span class="line"> wakeonlan:</span><br><span class="line"> mac: '00:f0:d2:d0:a0:0e'</span><br><span class="line"> broadcast: 255.255.255.255</span><br><span class="line"> delegate_to: localhost</span><br><span class="line"> - wakeonlan:</span><br><span class="line"> mac: '00:f0:d2:d0:a0:0e'</span><br><span class="line"> port: 9</span><br><span class="line"> delegate_to: localhost</span><br></pre></td></tr></table></figure>
<p>after running</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">anna@ansible-controller:/tmp$ ansible-playbook wakeonlan.yml </span><br><span class="line"></span><br><span class="line">PLAY [power on] ********************************************************************************************************</span><br><span class="line"></span><br><span class="line">TASK [Send a magic Wake-on-LAN packet to 00:00:5E:00:53:66] ************************************************************</span><br><span class="line">changed: [cube4200 -> localhost]</span><br><span class="line"></span><br><span class="line">TASK [wakeonlan] *******************************************************************************************************</span><br><span class="line">changed: [cube4200 -> localhost]</span><br><span class="line"></span><br><span class="line">PLAY RECAP *************************************************************************************************************</span><br><span class="line">cube4200 : ok=2 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0</span><br></pre></td></tr></table></figure>
<p>waitting few seconds, I can ssh to cube4200</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">anna@ansible-controller:/tmp$ ssh anna@cube4200</span><br><span class="line">Last login: Thu Jun 18 00:56:29 2020 from 192.168.0.31</span><br></pre></td></tr></table></figure>
<p>Notice: <code>gather_facts: no</code> must be configured. Because <code>gather_facts</code> default is yes, so when playbook is excuted, it will gather facts from remote, which is not power on yet, so ansible will output error message as following:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">anna@ansible-controller:/tmp$ ansible-playbook wakeonlan.yml </span><br><span class="line"></span><br><span class="line">PLAY [power on] ********************************************************************************************************</span><br><span class="line"></span><br><span class="line">TASK [Gathering Facts] *************************************************************************************************</span><br><span class="line">fatal: [cube4200]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: System is going down.\n\nConnection closed by 192.168.0.30 port 22", "unreachable": true}</span><br><span class="line"></span><br><span class="line">PLAY RECAP *************************************************************************************************************</span><br><span class="line">cube4200 : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0</span><br></pre></td></tr></table></figure>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="en">
<link itemprop="mainEntityOfPage" href="https://vmnet8.github.io/2020/06/16/Ansible-part10-net-tool-module-uri/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="Anna X">
<meta itemprop="description" content="Happy coding ...">
<meta itemprop="image" content="https://avatars0.githubusercontent.com/u/34552097">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="Anna X">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a href="/2020/06/16/Ansible-part10-net-tool-module-uri/" class="post-title-link" itemprop="url">Ansible-part10: net tool module uri</a>
</h1>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-06-16 19:40:45 / Modified: 19:50:38" itemprop="dateCreated datePublished" datetime="2020-06-16T19:40:45-07:00">2020-06-16</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-comment-o"></i>
</span>
<span class="post-meta-item-text">Disqus: </span>
<a title="disqus" href="/2020/06/16/Ansible-part10-net-tool-module-uri/#comments" itemprop="discussionUrl"><span class="post-comments-count disqus-comment-count" data-disqus-identifier="2020/06/16/Ansible-part10-net-tool-module-uri/" itemprop="commentCount"></span></a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>uri is a net tool moudle, which interacts with HTTP and HTTPS web services and supports Digest, Basic and WSSE HTTP authentication mechanisms.</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">tasks:</span><br><span class="line"> - name: Check that a page returns a status 200 </span><br><span class="line"> uri:</span><br><span class="line"> url: http://www.example.com</span><br><span class="line"> return_content: yes</span><br><span class="line"> register: this</span><br><span class="line"> - debug:</span><br><span class="line"> msg: "{{this}}"</span><br></pre></td></tr></table></figure>
<p>look at the output</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br></pre></td><td class="code"><pre><span class="line">anna@ansible-controller:~/Desktop/ansible-code/inventory/modules/net-tools-modules$ ansible-playbook site1.yml </span><br><span class="line"></span><br><span class="line">PLAY [uri] ********************************************************************************************************************************************************************************************************************************************</span><br><span class="line"></span><br><span class="line">TASK [Gathering Facts] ********************************************************************************************************************************************************************************************************************************</span><br><span class="line">ok: [cube4200]</span><br><span class="line">ok: [ansible-node1]</span><br><span class="line"></span><br><span class="line">TASK [Check that a page returns a status 200] *********************************************************************************************************************************************************************************************************</span><br><span class="line">ok: [cube4200]</span><br><span class="line">ok: [ansible-node1]</span><br><span class="line"></span><br><span class="line">TASK [debug] ******************************************************************************************************************************************************************************************************************************************</span><br><span class="line">ok: [ansible-node1] => {</span><br><span class="line"> "msg": {</span><br><span class="line"> "accept_ranges": "bytes", </span><br><span class="line"> "age": "478999", </span><br><span class="line"> "cache_control": "max-age=604800", </span><br><span class="line"> "changed": false, </span><br><span class="line"> "connection": "close", </span><br><span class="line"> "content": "<!doctype html>\n<html>\n<head>\n <title>Example Domain</title>\n\n <meta charset=\"utf-8\" />\n <meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <style type=\"text/css\">\n body {\n background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n \n }\n div {\n width: 600px;\n margin: 5em auto;\n padding: 2em;\n background-color: #fdfdff;\n border-radius: 0.5em;\n box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n }\n a:link, a:visited {\n color: #38488f;\n text-decoration: none;\n }\n @media (max-width: 700px) {\n div {\n margin: 0 auto;\n width: auto;\n }\n }\n </style> \n</head>\n\n<body>\n<div>\n <h1>Example Domain</h1>\n <p>This domain is for use in illustrative examples in documents. You may use this\n domain in literature without prior coordination or asking for permission.</p>\n <p><a href=\"https://www.iana.org/domains/example\">More information...</a></p>\n</div>\n</body>\n</html>\n", </span><br><span class="line"> "content_length": "1256", </span><br><span class="line"> "content_type": "text/html; charset=UTF-8", </span><br><span class="line"> "cookies": {}, </span><br><span class="line"> "cookies_string": "", </span><br><span class="line"> "date": "Wed, 17 Jun 2020 02:39:51 GMT", </span><br><span class="line"> "elapsed": 0, </span><br><span class="line"> "etag": "\"3147526947\"", </span><br><span class="line"> "expires": "Wed, 24 Jun 2020 02:39:51 GMT", </span><br><span class="line"> "failed": false, </span><br><span class="line"> "last_modified": "Thu, 17 Oct 2019 07:18:26 GMT", </span><br><span class="line"> "msg": "OK (1256 bytes)", </span><br><span class="line"> "redirected": false, </span><br><span class="line"> "server": "ECS (sjc/4E44)", </span><br><span class="line"> "status": 200, </span><br><span class="line"> "url": "http://www.example.com", </span><br><span class="line"> "vary": "Accept-Encoding", </span><br><span class="line"> "x_cache": "HIT"</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line">ok: [cube4200] => {</span><br><span class="line"> "msg": {</span><br><span class="line"> "accept_ranges": "bytes", </span><br><span class="line"> "age": "478426", </span><br><span class="line"> "cache_control": "max-age=604800", </span><br><span class="line"> "changed": false, </span><br><span class="line"> "connection": "close", </span><br><span class="line"> "content": "<!doctype html>\n<html>\n<head>\n <title>Example Domain</title>\n\n <meta charset=\"utf-8\" />\n <meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <style type=\"text/css\">\n body {\n background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n \n }\n div {\n width: 600px;\n margin: 5em auto;\n padding: 2em;\n background-color: #fdfdff;\n border-radius: 0.5em;\n box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n }\n a:link, a:visited {\n color: #38488f;\n text-decoration: none;\n }\n @media (max-width: 700px) {\n div {\n margin: 0 auto;\n width: auto;\n }\n }\n </style> \n</head>\n\n<body>\n<div>\n <h1>Example Domain</h1>\n <p>This domain is for use in illustrative examples in documents. You may use this\n domain in literature without prior coordination or asking for permission.</p>\n <p><a href=\"https://www.iana.org/domains/example\">More information...</a></p>\n</div>\n</body>\n</html>\n", </span><br><span class="line"> "content_length": "1256", </span><br><span class="line"> "content_type": "text/html; charset=UTF-8", </span><br><span class="line"> "cookies": {}, </span><br><span class="line"> "cookies_string": "", </span><br><span class="line"> "date": "Wed, 17 Jun 2020 02:39:50 GMT", </span><br><span class="line"> "elapsed": 0, </span><br><span class="line"> "etag": "\"3147526947\"", </span><br><span class="line"> "expires": "Wed, 24 Jun 2020 02:39:50 GMT", </span><br><span class="line"> "failed": false, </span><br><span class="line"> "last_modified": "Thu, 17 Oct 2019 07:18:26 GMT", </span><br><span class="line"> "msg": "OK (1256 bytes)", </span><br><span class="line"> "redirected": false, </span><br><span class="line"> "server": "ECS (sjc/4E76)", </span><br><span class="line"> "status": 200, </span><br><span class="line"> "url": "http://www.example.com", </span><br><span class="line"> "vary": "Accept-Encoding", </span><br><span class="line"> "x_cache": "HIT"</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">PLAY RECAP ********************************************************************************************************************************************************************************************************************************************</span><br><span class="line">ansible-node1 : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 </span><br><span class="line">cube4200 : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0</span><br></pre></td></tr></table></figure>
<p>Notice: if there is no <code>return_content: yes</code>, the output will only parts of above info.<br>the status is 200, which means it is normal.</p>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="en">
<link itemprop="mainEntityOfPage" href="https://vmnet8.github.io/2020/06/16/Ansible-part9-fetch-url-module/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="Anna X">
<meta itemprop="description" content="Happy coding ...">
<meta itemprop="image" content="https://avatars0.githubusercontent.com/u/34552097">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="Anna X">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a href="/2020/06/16/Ansible-part9-fetch-url-module/" class="post-title-link" itemprop="url">Ansible part9: fetch file from remote</a>
</h1>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-06-16 18:07:35 / Modified: 18:38:55" itemprop="dateCreated datePublished" datetime="2020-06-16T18:07:35-07:00">2020-06-16</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-comment-o"></i>
</span>
<span class="post-meta-item-text">Disqus: </span>
<a title="disqus" href="/2020/06/16/Ansible-part9-fetch-url-module/#comments" itemprop="discussionUrl"><span class="post-comments-count disqus-comment-count" data-disqus-identifier="2020/06/16/Ansible-part9-fetch-url-module/" itemprop="commentCount"></span></a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>file module has a fetch module, which is the same as copy but in reverse.</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">tasks:</span><br><span class="line"> - name: fetech</span><br><span class="line"> fetch: </span><br><span class="line"> src: /tmp/ansible-file-test.txt</span><br><span class="line"> dest: /tmp/</span><br><span class="line"> flat:</span><br></pre></td></tr></table></figure>
<p>go to my local machine to see /tmp directory</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">anna@ansible-controller:~/Desktop/ansible-code/inventory/modules/files-modules/inventory$ ll /tmp/ansible-node1/tmp/ansible-file-test.txt </span><br><span class="line">-rw-rw-r-- 1 anna anna 10 Jun 16 18:18 /tmp/ansible-node1/tmp/ansible-file-test.txt</span><br><span class="line">anna@ansible-controller:~/Desktop/ansible-code/inventory/modules/files-modules/inventory$ ll /tmp/cube4200/tmp/ansible-file-test.txt </span><br><span class="line">-rw-rw-r-- 1 anna anna 0 Jun 16 18:18 /tmp/cube4200/tmp/ansible-file-test.txt</span><br></pre></td></tr></table></figure>
<p>there are two hosts directories which are relate to my two hosts.</p>
<p>for the <code>flat</code>, it means ansible will not distinct the files from different hosts, the latest file will overwrite the old one.<br>for example</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">tasks:</span><br><span class="line"> - name: fetech</span><br><span class="line"> fetch: </span><br><span class="line"> src: /tmp/ansible-file-test.txt</span><br><span class="line"> dest: /tmp/</span><br><span class="line"> flat: yes</span><br></pre></td></tr></table></figure>
<p>notice: the default of flat is no, I am turning on it here, it will let the new file overwrite old file</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">anna@ansible-controller:~/Desktop/ansible-code/inventory/modules/files-modules/inventory$ ll /tmp</span><br><span class="line">total 76</span><br><span class="line">drwxrwxrwt 18 root root 4096 Jun 16 18:28 ./</span><br><span class="line">drwxr-xr-x 24 root root 4096 Jun 9 20:21 ../</span><br><span class="line">-rw-rw-r-- 1 anna anna 0 Jun 16 18:28 ansible-file-test.txt</span><br></pre></td></tr></table></figure>
<p>from above, I can see there is only one <code>ansible-file-test.txt</code> file which is from cube4200, and there is no file from ansible-node1.</p>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="en">
<link itemprop="mainEntityOfPage" href="https://vmnet8.github.io/2020/06/13/Ansible-part8-Ansible-lint/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="Anna X">
<meta itemprop="description" content="Happy coding ...">
<meta itemprop="image" content="https://avatars0.githubusercontent.com/u/34552097">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="Anna X">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a href="/2020/06/13/Ansible-part8-Ansible-lint/" class="post-title-link" itemprop="url">Ansible-part8: Ansible lint</a>
</h1>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-06-13 20:35:22 / Modified: 23:48:42" itemprop="dateCreated datePublished" datetime="2020-06-13T20:35:22-07:00">2020-06-13</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-comment-o"></i>
</span>
<span class="post-meta-item-text">Disqus: </span>
<a title="disqus" href="/2020/06/13/Ansible-part8-Ansible-lint/#comments" itemprop="discussionUrl"><span class="post-comments-count disqus-comment-count" data-disqus-identifier="2020/06/13/Ansible-part8-Ansible-lint/" itemprop="commentCount"></span></a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>Ansible lint: Ansible Lint is a commandline tool for linting playbooks. Use it to detect behaviors and practices that could potentially be improved.</p>
<h4 id="Install"><a href="#Install" class="headerlink" title="Install"></a>Install</h4><p>At first I try to Use pip install ansible-int, it failed.<br>then I try the apt install.</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">anna@ansible-controller:~/Desktop/ansible-code/inventory/modules/set-fact module$ sudo apt install ansible-lint</span><br><span class="line">[sudo] password for anna: </span><br><span class="line">Reading package lists... Done</span><br><span class="line">Building dependency tree </span><br><span class="line">Reading state information... Done</span><br><span class="line">The following packages were automatically installed and are no longer required:</span><br><span class="line"> golang-1.10-go golang-1.10-race-detector-runtime golang-1.10-src golang-race-detector-runtime golang-src ieee-data pkg-config python-certifi python-chardet python-jmespath python-kerberos python-libcloud python-lockfile python-netaddr</span><br><span class="line"> python-openssl python-requests python-selinux python-simplejson python-urllib3 python-xmltodict</span><br><span class="line">Use 'sudo apt autoremove' to remove them.</span><br><span class="line">The following NEW packages will be installed:</span><br><span class="line"> ansible-lint</span><br><span class="line">0 upgraded, 1 newly installed, 0 to remove and 34 not upgraded.</span><br><span class="line">Need to get 24.8 kB of archives.</span><br><span class="line">After this operation, 146 kB of additional disk space will be used.</span><br><span class="line">Get:1 http://us.archive.ubuntu.com/ubuntu bionic/universe amd64 ansible-lint all 3.4.20+git.20180203-1 [24.8 kB]</span><br><span class="line">Fetched 24.8 kB in 0s (76.1 kB/s) </span><br><span class="line">Selecting previously unselected package ansible-lint.</span><br><span class="line">(Reading database ... 240199 files and directories currently installed.)</span><br><span class="line">Preparing to unpack .../ansible-lint_3.4.20+git.20180203-1_all.deb ...</span><br><span class="line">Unpacking ansible-lint (3.4.20+git.20180203-1) ...</span><br><span class="line">Setting up ansible-lint (3.4.20+git.20180203-1) ...</span><br><span class="line">Processing triggers for man-db (2.8.3-2ubuntu0.1) ...</span><br><span class="line">anna@ansible-controller:~/Desktop/ansible-code/inventory/modules/set-fact module$ ansible-lint --version</span><br><span class="line">ansible-lint 3.4.20</span><br></pre></td></tr></table></figure>
<p>It shows the lint version is 3.4.20</p>
<h4 id="use-lint-to-test-yml-file"><a href="#use-lint-to-test-yml-file" class="headerlink" title="use lint to test yml file"></a>use lint to test yml file</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"></span><br><span class="line">anna@ansible-controller:~/Desktop/ansible-code/inventory/modules/packaging_modules/inventory$ ansible-lint site.yml</span><br><span class="line">[ANSIBLE0002] Trailing whitespace</span><br><span class="line">site.yml:10</span><br><span class="line"> name: </span><br><span class="line"></span><br><span class="line">[ANSIBLE0010] Package installs should not use latest</span><br><span class="line">site.yml:16</span><br><span class="line">Task/Handler: test apt module</span><br></pre></td></tr></table></figure>
<p>then I go to line 10 to add ‘test package module’ after name, and save playbook.<br>after run ansible-lint</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">anna@ansible-controller:~/Desktop/ansible-code/inventory/modules/packaging_modules/inventory$ ansible-lint site.yml</span><br><span class="line">[ANSIBLE0010] Package installs should not use latest</span><br><span class="line">site.yml:16</span><br><span class="line">Task/Handler: test apt module</span><br></pre></td></tr></table></figure>
<p>It only shows the second code which needs improved. </p>
<p>after I commented out the <code>state: latest</code>, the output of <code>ansible-lint site.yml</code> shows nothing, which means nothing needs improve in this site.yml file.</p>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="en">
<link itemprop="mainEntityOfPage" href="https://vmnet8.github.io/2020/06/13/Ansible-part7-set-facts-set-variable/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="Anna X">
<meta itemprop="description" content="Happy coding ...">
<meta itemprop="image" content="https://avatars0.githubusercontent.com/u/34552097">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="Anna X">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a href="/2020/06/13/Ansible-part7-set-facts-set-variable/" class="post-title-link" itemprop="url">Ansible-part7: set facts, set variable</a>
</h1>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-06-13 13:09:18 / Modified: 15:15:36" itemprop="dateCreated datePublished" datetime="2020-06-13T13:09:18-07:00">2020-06-13</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-comment-o"></i>
</span>
<span class="post-meta-item-text">Disqus: </span>
<a title="disqus" href="/2020/06/13/Ansible-part7-set-facts-set-variable/#comments" itemprop="discussionUrl"><span class="post-comments-count disqus-comment-count" data-disqus-identifier="2020/06/13/Ansible-part7-set-facts-set-variable/" itemprop="commentCount"></span></a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h4 id="what-is-set-fact"><a href="#what-is-set-fact" class="headerlink" title="what is set_fact"></a>what is set_fact</h4><p>Set fact is a module which allows setting new variables. These variables are set on a host-by-host base just like facts discovered by the setup module.</p>
<p>In ansible, there are some default info of hosts in <code>hostvars</code> variable, such as “ansible_check_mode”, “group_names” etc, and also the “ansible_facts”, which is not default show up, only when <code>gather_facts</code> is set to “yes”, it will show the details of ansible_fact. Except these two kinds of info, I can also use set_fact module to create my own info pair.</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">- name: set fact</span><br><span class="line"> hosts: all</span><br><span class="line"> gather_facts: no</span><br><span class="line"></span><br><span class="line"> tasks:</span><br><span class="line"> - name: gather facts</span><br><span class="line"> debug:</span><br><span class="line"> var: hostvars[ansible_host] #ansible_host is variable name, which means cube4200 and ansible-node1 in this case</span><br></pre></td></tr></table></figure>
<p>Let’s look at he output of this playbook,</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br></pre></td><td class="code"><pre><span class="line">anna@ansible-controller:~/Desktop/ansible-code/inventory/modules/set-fact module$ ansible-playbook site.yml </span><br><span class="line"></span><br><span class="line">PLAY [set fact] ************************************************************************</span><br><span class="line"></span><br><span class="line">TASK [gather facts] ********************************************************************</span><br><span class="line">ok: [cube4200] => {</span><br><span class="line"> "hostvars[ansible_host]": {</span><br><span class="line"> "ansible_check_mode": false, </span><br><span class="line"> "ansible_connection": "ssh", </span><br><span class="line"> "ansible_diff_mode": false, </span><br><span class="line"> "ansible_facts": {}, </span><br><span class="line"> "ansible_forks": 5, </span><br><span class="line"> "ansible_inventory_sources": [</span><br><span class="line"> "/home/anna/Desktop/ansible-code/inventory/modules/set-fact module/hosts"</span><br><span class="line"> ], </span><br><span class="line"> "ansible_playbook_python": "/usr/bin/python2", </span><br><span class="line"> "ansible_run_tags": [</span><br><span class="line"> "all"</span><br><span class="line"> ], </span><br><span class="line"> "ansible_skip_tags": [], </span><br><span class="line"> "ansible_user": "anna", </span><br><span class="line"> "ansible_verbosity": 0, </span><br><span class="line"> "ansible_version": {</span><br><span class="line"> "full": "2.9.9", </span><br><span class="line"> "major": 2, </span><br><span class="line"> "minor": 9, </span><br><span class="line"> "revision": 9, </span><br><span class="line"> "string": "2.9.9"</span><br><span class="line"> }, </span><br><span class="line"> "group_names": [</span><br><span class="line"> "web2"</span><br><span class="line"> ], </span><br><span class="line"> "groups": {</span><br><span class="line"> "all": [</span><br><span class="line"> "cube4200", </span><br><span class="line"> "ansible-node1"</span><br><span class="line"> ], </span><br><span class="line"> "ungrouped": [], </span><br><span class="line"> "web1": [</span><br><span class="line"> "ansible-node1"</span><br><span class="line"> ], </span><br><span class="line"> "web2": [</span><br><span class="line"> "cube4200"</span><br><span class="line"> ]</span><br><span class="line"> }, </span><br><span class="line"> "inventory_dir": "/home/anna/Desktop/ansible-code/inventory/modules/set-fact module", </span><br><span class="line"> "inventory_file": "/home/anna/Desktop/ansible-code/inventory/modules/set-fact module/hosts", </span><br><span class="line"> "inventory_hostname": "cube4200", </span><br><span class="line"> "inventory_hostname_short": "cube4200", </span><br><span class="line"> "omit": "__omit_place_holder__a53469922527cea947bde7fea01f0f911fe92d8c", </span><br><span class="line"> "playbook_dir": "/home/anna/Desktop/ansible-code/inventory/modules/set-fact module"</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line">ok: [ansible-node1] => {</span><br><span class="line"> "hostvars[ansible_host]": {</span><br><span class="line"> "ansible_check_mode": false, </span><br><span class="line"> "ansible_connection": "ssh", </span><br><span class="line"> "ansible_diff_mode": false, </span><br><span class="line"> "ansible_facts": {}, </span><br><span class="line"> "ansible_forks": 5, </span><br><span class="line"> "ansible_inventory_sources": [</span><br><span class="line"> "/home/anna/Desktop/ansible-code/inventory/modules/set-fact module/hosts"</span><br><span class="line"> ], </span><br><span class="line"> "ansible_playbook_python": "/usr/bin/python2", </span><br><span class="line"> "ansible_run_tags": [</span><br><span class="line"> "all"</span><br><span class="line"> ], </span><br><span class="line"> "ansible_skip_tags": [], </span><br><span class="line"> "ansible_user": "pi", </span><br><span class="line"> "ansible_verbosity": 0, </span><br><span class="line"> "ansible_version": {</span><br><span class="line"> "full": "2.9.9", </span><br><span class="line"> "major": 2, </span><br><span class="line"> "minor": 9, </span><br><span class="line"> "revision": 9, </span><br><span class="line"> "string": "2.9.9"</span><br><span class="line"> }, </span><br><span class="line"> "group_names": [</span><br><span class="line"> "web1"</span><br><span class="line"> ], </span><br><span class="line"> "groups": {</span><br><span class="line"> "all": [</span><br><span class="line"> "cube4200", </span><br><span class="line"> "ansible-node1"</span><br><span class="line"> ], </span><br><span class="line"> "ungrouped": [], </span><br><span class="line"> "web1": [</span><br><span class="line"> "ansible-node1"</span><br><span class="line"> ], </span><br><span class="line"> "web2": [</span><br><span class="line"> "cube4200"</span><br><span class="line"> ]</span><br><span class="line"> }, </span><br><span class="line"> "inventory_dir": "/home/anna/Desktop/ansible-code/inventory/modules/set-fact module", </span><br><span class="line"> "inventory_file": "/home/anna/Desktop/ansible-code/inventory/modules/set-fact module/hosts", </span><br><span class="line"> "inventory_hostname": "ansible-node1", </span><br><span class="line"> "inventory_hostname_short": "ansible-node1", </span><br><span class="line"> "omit": "__omit_place_holder__a53469922527cea947bde7fea01f0f911fe92d8c", </span><br><span class="line"> "playbook_dir": "/home/anna/Desktop/ansible-code/inventory/modules/set-fact module"</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">PLAY RECAP *****************************************************************************</span><br><span class="line">ansible-node1 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 </span><br><span class="line">cube4200 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0</span><br></pre></td></tr></table></figure>
<p>eventhought <code>gather_facts</code> is “no”, ansible still show some basic info of every hosts.<br>If <code>gather_facts</code> is “yes”, except the default info, ansible will show <code>ansible-facts</code> info which included a lots of system info of every hosts.</p>
<!--noindex-->
<div class="post-button">
<a class="btn" href="/2020/06/13/Ansible-part7-set-facts-set-variable/#more" rel="contents">
Read more »
</a>
</div>
<!--/noindex-->
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="en">
<link itemprop="mainEntityOfPage" href="https://vmnet8.github.io/2020/06/03/Ansible-part6-ansible-vault-encrypt-file/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="Anna X">
<meta itemprop="description" content="Happy coding ...">
<meta itemprop="image" content="https://avatars0.githubusercontent.com/u/34552097">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="Anna X">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a href="/2020/06/03/Ansible-part6-ansible-vault-encrypt-file/" class="post-title-link" itemprop="url">Ansible part6: ansible vault encrypt file</a>
</h1>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-06-03 00:24:34 / Modified: 14:47:15" itemprop="dateCreated datePublished" datetime="2020-06-03T00:24:34-07:00">2020-06-03</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-comment-o"></i>
</span>
<span class="post-meta-item-text">Disqus: </span>
<a title="disqus" href="/2020/06/03/Ansible-part6-ansible-vault-encrypt-file/#comments" itemprop="discussionUrl"><span class="post-comments-count disqus-comment-count" data-disqus-identifier="2020/06/03/Ansible-part6-ansible-vault-encrypt-file/" itemprop="commentCount"></span></a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>Ansible Vault is a feature of ansible that allows you to keep sensitive data such as passwords or keys in encrypted files, rather than as plaintext in playbooks or roles. These vault files can then be distributed or placed in source control.</p>
<h4 id="encrypt-a-file-using-ansible-vault"><a href="#encrypt-a-file-using-ansible-vault" class="headerlink" title="encrypt a file using ansible-vault"></a>encrypt a file using ansible-vault</h4><p>I created a vars file to test ansible-vault command</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">port: 443</span><br><span class="line">greeting: "greeting from vars file"</span><br><span class="line">ansible_user: pi</span><br></pre></td></tr></table></figure>
<!--noindex-->
<div class="post-button">
<a class="btn" href="/2020/06/03/Ansible-part6-ansible-vault-encrypt-file/#more" rel="contents">
Read more »
</a>
</div>
<!--/noindex-->
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="en">
<link itemprop="mainEntityOfPage" href="https://vmnet8.github.io/2020/06/02/Ansible-part5-how-to-use-module/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="Anna X">
<meta itemprop="description" content="Happy coding ...">
<meta itemprop="image" content="https://avatars0.githubusercontent.com/u/34552097">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="Anna X">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a href="/2020/06/02/Ansible-part5-how-to-use-module/" class="post-title-link" itemprop="url">Ansible part5: how to use module - command module and register and return value of module</a>
</h1>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Created: 2020-06-02 14:03:25" itemprop="dateCreated datePublished" datetime="2020-06-02T14:03:25-07:00">2020-06-02</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-check-o"></i>
</span>
<span class="post-meta-item-text">Edited on</span>