WEBVTT

1
00:00.000 --> 00:02.480
Okay, so let's walk through this solution then.

2
00:02.480 --> 00:05.520
So the very first thing that I'm going to have to do is to use Ansible Nav

3
00:05.520 --> 00:06.400
igator to display

4
00:06.400 --> 00:10.880
my inventory in both JSON and YAML formats.

5
00:10.880 --> 00:15.990
So the command I can use is Ansible Navigator Inventory and then -i and then

6
00:15.990 --> 00:16.500
provide my

7
00:16.500 --> 00:20.240
inventory which is called in my case here, inventory.ini.

8
00:20.240 --> 00:24.500
Then I'm going to use standard out to print it to the terminal and I'm going to

9
00:24.500 --> 00:25.480
say - -list.

10
00:25.480 --> 00:30.370
And when I do this, what we actually see here is the contents of our inventory
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

10
00:25.480 --> 00:30.370
And when I do this, what we actually see here is the contents of our inventory

11
00:30.370 --> 00:31.720
in JSON format.

12
00:31.720 --> 00:36.550
Now if I want to see in YAML format, I can say -y and that will transform the

13
00:36.550 --> 00:36.960
data to

14
00:36.960 --> 00:38.960
be rendered as YAML.

15
00:38.960 --> 00:40.600
So that is the first thing we had to do.

16
00:40.600 --> 00:43.700
The next thing we're going to have to do is to open the documentation for the

17
00:43.700 --> 00:44.160
built-in

18
00:44.160 --> 00:46.440
debug module directly on the terminal.

19
00:46.440 --> 00:51.020
So what I will do is I will say Ansible.doc -L to get a list and we can see the

20
00:51.020 --> 00:52.000
debug module

21
00:52.000 --> 00:53.480
is this one right here.

22
00:53.480 --> 00:57.350
So let's just grab this, copy here, press Q2Quit, clear the screen, we'll just

23
00:57.350 --> 00:58.840
say Ansible.doc

24
00:58.840 --> 01:02.690
and then paste in the name of this particular module and now we have access to
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

24
00:58.840 --> 01:02.690
and then paste in the name of this particular module and now we have access to

25
01:02.690 --> 01:03.720
the documentation

26
01:03.720 --> 01:05.760
for that debug module right there.

27
01:05.760 --> 01:09.660
So once again Q2Quit, what I'm going to have to do now is to create a file on

28
01:09.660 --> 01:10.240
one of my

29
01:10.240 --> 01:14.400
managed devices called temp validation-check.txt.

30
01:14.400 --> 01:17.180
So in my case here, I will choose the yellow box, doesn't actually matter which

31
01:17.180 --> 01:17.560
one you

32
01:17.560 --> 01:21.710
pick and all I will do is I'll go to the temp directory or rather forward slash

33
01:21.710 --> 01:22.080
temp

34
01:22.080 --> 01:29.260
and I will just say touch validation-check.txt if I don't ls, now the file is

35
01:29.260 --> 01:30.040
present.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

35
01:29.260 --> 01:30.040
present.

36
01:30.040 --> 01:32.530
So the next thing I'm going to have to do is to create a playbook that is going

37
01:32.530 --> 01:32.920
to check

38
01:32.920 --> 01:35.840
for the presence of this particular file on both machines.

39
01:35.840 --> 01:39.840
That means it should find it on the yellow box but not find it on the blue box.

40
01:39.840 --> 01:43.580
So back to the control node, let me just create a file called validation.yml

41
01:43.580 --> 01:43.960
from my

42
01:43.960 --> 01:47.520
playbook, going to insert mode to have my three hyphens and I'll give this a

43
01:47.520 --> 01:48.000
name and

44
01:48.000 --> 01:50.080
just call this validation play.

45
01:50.080 --> 01:53.560
Now I'm going to check it on both of my devices so I will set my horse to be

46
01:53.560 --> 01:53.960
all.

47
01:53.960 --> 01:57.020
I'm going to set gather facts to false not that it's necessary but it does

48
01:57.020 --> 01:57.680
speed things

49
01:57.680 --> 02:00.360
up and now I define my tasks.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

49
01:57.680 --> 02:00.360
up and now I define my tasks.

50
02:00.360 --> 02:04.500
So I will give the task a name and I'll just say check the validation file

51
02:04.500 --> 02:05.240
exists.

52
02:05.240 --> 02:08.920
Now the module I'm going to use is going to be the Ansible built in stat module

53
02:08.920 --> 02:09.040
and the

54
02:09.040 --> 02:14.980
path I'm going to provide here is forward slash temp forward slash validation-

55
02:14.980 --> 02:16.040
check.txt.

56
02:16.040 --> 02:19.740
Now to capture the output I will use the register module and I'll just call

57
02:19.740 --> 02:21.240
this stat output.

58
02:21.240 --> 02:24.680
Now I'll have a new task and I'll just call this print the result.

59
02:24.680 --> 02:28.490
So I'll use the debug module with the var parameter and all I want to do is to

60
02:28.490 --> 02:28.880
print

61
02:28.880 --> 02:29.880
stat outputs.

62
02:29.880 --> 02:34.320
Now if I press escape call on wq to write and quit we now have this playbook.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

62
02:29.880 --> 02:34.320
Now if I press escape call on wq to write and quit we now have this playbook.

63
02:34.320 --> 02:39.030
Now what we actually want to do is we want to run this playbook within an Ans

64
02:39.030 --> 02:40.160
ible Navigator

65
02:40.160 --> 02:41.160
execution environment.

66
02:41.160 --> 02:46.790
So what I will do here is say Ansible Navigator run validation.yml and to get

67
02:46.790 --> 02:47.800
the output on

68
02:47.800 --> 02:51.780
my terminal as normal I will say -m s to the out that's just a preference you

69
02:51.780 --> 02:52.200
don't

70
02:52.200 --> 02:53.200
have to do this.

71
02:53.200 --> 02:57.290
So if I enter give it a moment the playbook executes and as we can see here we

72
02:57.290 --> 02:58.480
have a result.

73
02:58.480 --> 03:02.690
So if I scroll on up for the yellow box we can see the stat output has a whole
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

73
02:58.480 --> 03:02.690
So if I scroll on up for the yellow box we can see the stat output has a whole

74
03:02.690 --> 03:03.120
bunch

75
03:03.120 --> 03:07.090
of information that's because the file does exist right here and we can confirm

76
03:07.090 --> 03:07.640
this via

77
03:07.640 --> 03:11.570
the fact that the exist key is set to the value of true whereas if I scroll on

78
03:11.570 --> 03:12.440
up to the blue

79
03:12.440 --> 03:15.920
box just a little bit higher we can see here the blue box.

80
03:15.920 --> 03:20.560
The stat module is telling us that this file does not exist on this particular

81
03:20.560 --> 03:21.240
device.

82
03:21.240 --> 03:24.700
So that is us for our validation challenge I hope this has been informative for

83
03:24.700 --> 03:25.120
you and

84
03:25.120 --> 03:26.440
I'd like to thank you for viewing.
