WEBVTT

1
00:00.000 --> 00:02.640
Okay, so let's walk through the validation challenge.

2
00:02.640 --> 00:05.440
The very first thing we're going to have to do is to write a playbook that is

3
00:05.440 --> 00:05.760
going to

4
00:05.760 --> 00:09.800
install the Redis package on both managed devices and ensure the service has

5
00:09.800 --> 00:10.240
started

6
00:10.240 --> 00:14.160
and will automatically start every time the system is rebooted.

7
00:14.160 --> 00:18.870
So what I will do here is create a playbook, let's just call this validation1.Y

8
00:18.870 --> 00:19.280
ML.

9
00:19.280 --> 00:23.840
We're going to insert modes and let's just call this validation play1.

10
00:23.840 --> 00:28.080
I'm going to target the all group and I'll set my gather facts to be false.

11
00:28.080 --> 00:32.400
Now what I'll do is define my tasks and this task will be called installRedis.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

11
00:28.080 --> 00:32.400
Now what I'll do is define my tasks and this task will be called installRedis.

12
00:32.400 --> 00:35.920
So in order to install Redis I will use the dnf module,

13
00:35.920 --> 00:38.560
it's also answerable built-in dnf.

14
00:38.560 --> 00:42.800
The name is going to be Redis and I want the state to be present.

15
00:42.800 --> 00:46.160
Now I want to ensure that the service is started and enabled.

16
00:46.160 --> 00:49.760
So I'll use the built-in service module right here and the name of the service

17
00:49.760 --> 00:50.880
will be Redis.

18
00:50.880 --> 00:55.760
The state should be started and enabled should be set to the value true.

19
00:55.760 --> 00:59.360
So if I just save this here and I run the playbook and to enter,

20
00:59.360 --> 01:02.960
as we can see here we have now started and enabled Redis.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

20
00:59.360 --> 01:02.960
as we can see here we have now started and enabled Redis.

21
01:02.960 --> 01:06.240
Now the next task is to write another playbook that is going to manage the

22
01:06.240 --> 01:07.440
default boot target

23
01:07.440 --> 01:10.400
configuration and this playbook should be id important.

24
01:10.400 --> 01:13.520
So let's just call this one validation2.YML.

25
01:13.520 --> 01:18.160
We'll just call this manage boot target, the host I'm going to target, again

26
01:18.160 --> 01:19.120
will be all

27
01:19.120 --> 01:21.040
and gather facts as set to false.

28
01:21.040 --> 01:24.640
Now what I will do here is define a variable to specify what my default target

29
01:24.640 --> 01:25.680
should actually be.

30
01:25.680 --> 01:28.960
And in this case here I will just set it to be graphical.target.

31
01:28.960 --> 01:32.400
Now I'll define my tasks and I'm going to use the Ansible built-in command
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

31
01:28.960 --> 01:32.400
Now I'll define my tasks and I'm going to use the Ansible built-in command

32
01:32.400 --> 01:32.800
module

33
01:32.800 --> 01:37.440
and the command I'm going to run is systemctl gets hyping default.

34
01:37.440 --> 01:41.200
I'll use the changed when parameter and set the value to false.

35
01:41.200 --> 01:46.480
I'm going to register the output as default outputs and I'll use the Ansible

36
01:46.480 --> 01:46.960
built-in

37
01:46.960 --> 01:51.680
debug module and all I'm going to print out is the default output variable.

38
01:51.680 --> 01:55.360
Now I'll create a playbook to actually change the default value if required.

39
01:55.600 --> 01:58.320
Once again I'm going to use the built-in command module.

40
01:58.320 --> 02:02.580
This time though the command is going to be systemctl set hyping default and I
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

40
01:58.320 --> 02:02.580
This time though the command is going to be systemctl set hyping default and I

41
02:02.580 --> 02:03.600
'm going to use my

42
02:03.600 --> 02:07.850
double curly braces to pull in my default underscore target variable I have to

43
02:07.850 --> 02:08.400
find.

44
02:08.400 --> 02:12.560
I only want it to run on a conditional basis to ensure that it is id important

45
02:12.560 --> 02:18.970
and I'll specify when the default target variable is not in the default output.

46
02:18.970 --> 02:20.080
astdouts.

47
02:20.080 --> 02:23.560
And in fact let me just change the print statement to only print out the stdout

48
02:23.560 --> 02:24.320
attribute.

49
02:24.320 --> 02:26.960
So I'll notify my handler called reboot system.

50
02:26.960 --> 02:29.280
So now I'll create my handler go into spaces.

51
02:29.280 --> 02:33.280
The handler name will be reboot system and I'll use the Ansible built-in reboot
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

51
02:29.280 --> 02:33.280
The handler name will be reboot system and I'll use the Ansible built-in reboot

52
02:33.280 --> 02:33.920
module

53
02:33.920 --> 02:35.840
and I can specify the reboot timeout.

54
02:35.840 --> 02:40.240
So again I will set this at 60 seconds if you need longer then by all means set

55
02:40.240 --> 02:41.040
it to longer.

56
02:41.040 --> 02:46.000
So I'll just save this if I rerun the playbook and to enter as we can see here

57
02:46.000 --> 02:47.280
the playbook runs

58
02:47.280 --> 02:51.280
and because we have built in the idempotency we did not seek to make a change

59
02:51.280 --> 02:51.840
because the

60
02:51.840 --> 02:56.160
current target actually matches the default target that we desired and

61
02:56.160 --> 02:56.800
therefore of course we

62
02:56.800 --> 03:01.230
happen to specify we wanted a different value then we would invoke the set
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

62
02:56.800 --> 03:01.230
happen to specify we wanted a different value then we would invoke the set

63
03:01.230 --> 03:02.320
default command

64
03:02.320 --> 03:04.240
as well as calling your handler.

65
03:04.240 --> 03:08.000
So the next thing I'm going to do is to write a bash script called echo date SH

66
03:08.000 --> 03:08.000
.

67
03:08.000 --> 03:11.440
So let me just put this in the temp directory just for simplicity and I'll

68
03:11.440 --> 03:13.280
create echo date SH.

69
03:13.280 --> 03:17.360
So I'll have my shebang bin bash at the top and all I'm going to do is to echo

70
03:17.360 --> 03:18.800
out the content of

71
03:18.800 --> 03:22.480
my date and I will append it into a text file.

72
03:22.480 --> 03:26.200
So I'll just call this once again in the temp directory I'll just call this

73
03:26.200 --> 03:28.000
validation.txt

74
03:28.000 --> 03:31.520
And with that now created what I'm going to have to do is to write an Ansible
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

74
03:28.000 --> 03:31.520
And with that now created what I'm going to have to do is to write an Ansible

75
03:31.520 --> 03:32.400
playbook that is going

76
03:32.400 --> 03:35.520
to run this script on a daily basis.

77
03:35.520 --> 03:39.280
So we'll create a playbook called validation three we'll target the all group.

78
03:39.280 --> 03:40.960
I will define my tasks.

79
03:40.960 --> 03:44.160
The first thing I want to do is to ensure that the script is available on both

80
03:44.160 --> 03:45.280
of my devices.

81
03:45.280 --> 03:49.900
So I'll use the Ansible built in copy module and the source is going to be temp

82
03:49.900 --> 03:51.360
echo hyphen date

83
03:51.360 --> 03:55.960
dot SH and I'm going to copy that over to the same location on the managed

84
03:55.960 --> 03:56.480
devices.

85
03:56.480 --> 03:58.720
Let's make sure the script is executable.

86
03:58.720 --> 04:03.840
So I'll have the auto permissions 0755 and now I want to run the script on a
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

86
03:58.720 --> 04:03.840
So I'll have the auto permissions 0755 and now I want to run the script on a

87
04:03.840 --> 04:04.960
daily basis.

88
04:04.960 --> 04:07.760
So I want to use the Ansible built in cron module.

89
04:07.760 --> 04:12.240
The name is going to be daily execution of script and I'll specify that the

90
04:12.240 --> 04:13.280
special time is going to be

91
04:13.280 --> 04:17.040
the value of daily and now I will specify what the job actually is.

92
04:17.040 --> 04:20.000
So what I will do is I'll give the path to the script to be executed.

93
04:20.000 --> 04:21.440
So it's going to be in the temp directory.

94
04:21.440 --> 04:26.000
It's going to be echo date dot SH and I'll specify that the user is going to be

95
04:26.000 --> 04:26.160
the

96
04:26.160 --> 04:30.480
Ansible user and the last thing I will do is I will set gather facts to be the
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

96
04:26.160 --> 04:30.480
Ansible user and the last thing I will do is I will set gather facts to be the

97
04:30.480 --> 04:31.360
value false.

98
04:31.360 --> 04:32.480
So let's give this a go.

99
04:32.480 --> 04:37.570
If I say Ansible playbook validation three dot yml and to enter we copy over

100
04:37.570 --> 04:38.240
the script

101
04:38.240 --> 04:41.840
and now we schedule the script's execution to be run on a daily basis.

102
04:41.840 --> 04:43.280
So let's go to our devices.

103
04:43.280 --> 04:45.120
So let me become the Ansible user.

104
04:45.120 --> 04:46.560
Our login is Ansible.

105
04:46.560 --> 04:51.200
If I cd to the temp directory and I do an LS and I grip for echo,

106
04:51.200 --> 04:55.800
I should see my script right here and if as the Ansible user I say crontab dash

107
04:55.800 --> 04:56.400
l,

108
04:56.400 --> 05:00.350
we can actually see here we have a crontab schedule specified that we want to
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

108
04:56.400 --> 05:00.350
we can actually see here we have a crontab schedule specified that we want to

109
05:00.350 --> 05:00.960
have the daily

110
05:00.960 --> 05:02.880
execution of our script.

111
05:02.880 --> 05:05.200
So that is us for our validation challenge.

112
05:05.200 --> 05:08.240
I hope it's been informative for you and I'd like to thank you for viewing.
