WEBVTT

1
00:00.000 --> 00:03.000
So friends, let's walk through the validation challenge.

2
00:03.000 --> 00:06.400
The very first thing I'm going to have to do is to create custom facts on one

3
00:06.400 --> 00:07.500
of my devices.

4
00:07.500 --> 00:11.000
This file should be called validation with the correct extension.

5
00:11.000 --> 00:16.000
So what I will say is sudo mkdir -p to create a nested directory and I will say

6
00:16.000 --> 00:17.000
etse

7
00:17.000 --> 00:22.530
Ansible, fats.d and if I hit enter, now if I see the enter this particular

8
00:22.530 --> 00:23.000
directory,

9
00:23.000 --> 00:26.790
what I'm going to have to do is to create a file called validation with the

10
00:26.790 --> 00:27.500
correct extension.

11
00:27.500 --> 00:30.500
Now the extension is going to end in dot fact.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

11
00:27.500 --> 00:30.500
Now the extension is going to end in dot fact.

12
00:30.500 --> 00:35.200
So what I will do here is this sudo vim validation dot fact and I'm going to

13
00:35.200 --> 00:36.500
have to have a heading

14
00:36.500 --> 00:39.500
inside of this particular file known as nuggets.

15
00:39.500 --> 00:42.770
Okay. And then I'm going to have to create a key called Linux with a

16
00:42.770 --> 00:45.000
corresponding value of red hat.

17
00:45.000 --> 00:47.000
So let's just write and quit.

18
00:47.000 --> 00:50.580
Perfect. So now we should have to find that custom fact on this particular

19
00:50.580 --> 00:51.000
device.

20
00:51.000 --> 00:54.200
The next thing we're going to have to do is to use Ansible to retrieve this

21
00:54.200 --> 00:56.000
custom fact from the device.

22
00:56.000 --> 01:00.000
So let me just create a playbook called validation one dot yml.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

23
01:00.000 --> 01:01.500
Let's just call this validation.

24
01:01.500 --> 01:05.400
Now I can target the all group of ISO wish but in this case here, I'm just

25
01:05.400 --> 01:07.000
going to target the yellow box

26
01:07.000 --> 01:09.500
because that is a device whereby I have my custom fact.

27
01:09.500 --> 01:14.350
Now specify my tasks. I'll get the task in name and I'll just say print custom

28
01:14.350 --> 01:15.000
facts.

29
01:15.000 --> 01:18.500
So I'll use a debug module and let's just use the var parameter.

30
01:18.500 --> 01:22.000
And this time here I'm going to print out Ansible local care.

31
01:22.000 --> 01:26.240
So if I just write and quit and I run my validation playbook, I enter, we

32
01:26.240 --> 01:27.000
gather the facts.

33
01:27.000 --> 01:31.000
And as we can see here, we can print out our custom facts that we have to find.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

33
01:27.000 --> 01:31.000
And as we can see here, we can print out our custom facts that we have to find.

34
01:31.000 --> 01:34.330
Now the next thing we're going to have to do is to write a playbook that is

35
01:34.330 --> 01:35.500
going to run the pwd command

36
01:35.500 --> 01:38.000
against both managed devices and display the outputs.

37
01:38.000 --> 01:42.000
So what I will do is I will create a new playbook called validation to dot yml.

38
01:42.000 --> 01:45.800
Let's just call this validation to the host. I'm going to target will be the

39
01:45.800 --> 01:46.000
all.

40
01:46.000 --> 01:50.000
And in this case here, let me just say gather facts is equal to false.

41
01:50.000 --> 01:53.000
You don't actually have to do this, but it does make sense because it's going

42
01:53.000 --> 01:55.000
to speed things up now to find my tasks.

43
01:55.000 --> 02:00.200
The name is going to be run the pwd command and I want to use the ansible built
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

43
01:55.000 --> 02:00.200
The name is going to be run the pwd command and I want to use the ansible built

44
02:00.200 --> 02:01.000
in command module.

45
02:01.000 --> 02:04.430
And the command I'm going to run is going to be pwd and I actually want to

46
02:04.430 --> 02:08.000
capture this output utilizing the register keyword.

47
02:08.000 --> 02:12.000
And I'll just call this pwd outputs. Now I want to print the result of this

48
02:12.000 --> 02:12.000
output.

49
02:12.000 --> 02:15.000
So I'll create a new task. I'll just say print the outputs.

50
02:15.000 --> 02:19.830
And I'll use the debug module. And again, I can use the var parameter or if I

51
02:19.830 --> 02:22.000
so wish I can use the message parameter as well.

52
02:22.000 --> 02:24.630
And just use my double color braces. Let's do that for a little bit of

53
02:24.630 --> 02:25.000
variation.

54
02:25.000 --> 02:31.150
And I'm going to substitute in my pwd output. If I just write this and save,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

54
02:25.000 --> 02:31.150
And I'm going to substitute in my pwd output. If I just write this and save,

55
02:31.150 --> 02:33.000
let's run validation to now and to enter.

56
02:33.000 --> 02:36.050
As we can see here, we are running the command and if you want to be a little

57
02:36.050 --> 02:40.000
bit more explicit, what you could do, let's just grab the sdd out information

58
02:40.000 --> 02:41.000
to try again.

59
02:41.000 --> 02:45.250
There we have the result of the pwd command. We are in the home directory for

60
02:45.250 --> 02:46.000
Ansible.

61
02:46.000 --> 02:49.890
Now let's write one more playbook. It's called validation three. We'll target

62
02:49.890 --> 02:51.000
the host all.

63
02:51.000 --> 02:55.000
Let's set gather facts to false once again. And now we'll define our tasks.

64
02:55.000 --> 02:58.700
So what we're going to have to do is to create a directory. We'll use the ans

65
02:58.700 --> 03:00.000
ible built in file module.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

66
03:00.000 --> 03:05.480
The path is going to be forward slash temp forward slash validation. And the

67
03:05.480 --> 03:07.000
state is going to be directory.

68
03:07.000 --> 03:10.820
Now remember, what we want to do is we want to print a message saying that the

69
03:10.820 --> 03:13.000
validation directory has been created.

70
03:13.000 --> 03:17.000
But we only want to do it when the directory has been created.

71
03:17.000 --> 03:21.760
Pretty much we only want to do it when there happens to be a change, i.e. when

72
03:21.760 --> 03:23.000
this gets created.

73
03:23.000 --> 03:27.120
If we just run it again and already exists, the command or rather the message

74
03:27.120 --> 03:28.000
should not be printed.

75
03:28.000 --> 03:32.430
Therefore, we want to use the notify directive. That way we can call a
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

75
03:28.000 --> 03:32.430
Therefore, we want to use the notify directive. That way we can call a

76
03:32.430 --> 03:33.000
particular handler.

77
03:33.000 --> 03:38.030
Let's just say their message. And now at the same level of indentation as tasks

78
03:38.030 --> 03:39.000
, I'm going to define my handlers.

79
03:39.000 --> 03:43.580
And I'll just say the name is their message. And I'm going to use the debug

80
03:43.580 --> 03:44.000
module.

81
03:44.000 --> 03:49.000
And the message is going to be validation directory has been created.

82
03:49.000 --> 03:52.000
Okay, so let's save this. And let's run the playbook and enter.

83
03:52.000 --> 03:56.000
Now we create the directory as we can see here. This has been changed.

84
03:56.000 --> 04:00.300
And because we had a change, we have indeed printed out the message validation
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

84
03:56.000 --> 04:00.300
And because we had a change, we have indeed printed out the message validation

85
04:00.300 --> 04:01.000
directory has been created.

86
04:01.000 --> 04:05.780
Now because they already exist now, if I rerun the playbook, notice we no

87
04:05.780 --> 04:08.000
longer print out that message.

88
04:08.000 --> 04:11.620
So that is us for our validation challenge. I hope this has been informative

89
04:11.620 --> 04:12.000
for you.

90
04:12.000 --> 04:14.000
And I'd like to thank you for viewing.
