Introduction to Ansible Transcripts
Chapter: Ansible Core Concepts
0:00 Tasks are Ansible's building blocks
0:01 for accomplishing your objective.
0:05 Tasks are written in YAML and they are in the instructions
0:08 that invoke Ansible modules to execute an action.
0:11 We took a look at how these concepts
0:12 related in the first video
0:14 and we saw that there are modules for all sorts of actions
0:16 we want to take like working with Git
0:17 or installing and configuring Redis
0:20 and we needed a mechanism
0:21 to specify how to call those modules.
0:23 That's where tasks fit in.
0:25 Here's what a task looks like.
0:26 We start out with a -
0:28 and then a space and keyword name.
0:30 And we start with a human readable name.
0:32 Think of this as a comment.
0:33 Technically you don't have to start
0:34 your Ansible tasks with name
0:36 but as these tasks are running
0:38 having a comment on every single one
0:40 to explain what it's doing and why is really useful.
0:43 So the first line that we start out with
0:44 on the task is a name
0:46 what this task is doing, and why.
0:48 In this case, we're making sure that Git is installed
0:50 on the system as this can do one of two things.
0:52 First, it's going to check if Git is installed.
0:54 If it's installed, it's going to say hey, we're good.
0:56 Move on to the next task.
0:57 If it's not installed, it will handle installing it for you.
1:00 It does this by using the apt module.
1:02 So assuming we're on an Ubuntu system
1:04 or a Debian based installation
1:05 that has the aptitude package manager
1:07 we're using the apt module
1:09 and we're passing it three parameters.
1:11 The first is the name of the package that we want to install.
1:13 That would be git-core.
1:15 The state that we want it to be in.
1:16 In our case, we want the git-core package to be installed.
1:19 If we said state=absent
1:21 that would mean we do not want
1:22 the git-core package to be installed
1:24 and it would remove the package if it was installed.
1:26 And the third parameter that we're passing in
1:28 is to update the cache.
1:30 The cache contains a list of all the packages
1:32 that can be installed and their version numbers.
1:34 And we always want to grab
1:35 the very latest version of the git-core package.
1:37 So this ensures that the cache is updated
1:40 equivalent to running the sudo apt update command
1:43 before we check to see if git init is installed
1:45 and install it. And finally, become true specifies
1:48 we want to use our super user privileges
1:50 because apt requires super user privileges
1:52 to install our package.
1:53 That's what a task looks like written in YAML
1:55 and there's two ways we can execute this.
1:57 The most common is going to be in a playbook
1:59 where you have a bunch of tasks grouped together.
2:01 And the other way is we can run ad-hoc commands.
2:03 So let's run a couple of those
2:04 just so we can get comfortable
2:05 with how to invoke modules using tasks.