Introduction to Ansible Transcripts
Chapter: Ansible Core Concepts
Lecture: Modules

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We see how each of the Ansible core concepts relates to each other and fills a specific need for how to handle configuration management.
0:07 Now, let's take a look at each of these concepts individually, give them a clear concise definition so that we know what we're working with
0:13 and to take a look at some examples so that in the next chapter when we write our first playbook we at least have enough of an idea
0:19 of why we're working on each step. The first concept is modules. Modules are code provided by Ansible. Now, they're typically written in Python
0:26 and in fact, the core Ansible modules that are provided with the Ansible project when you install it, are all written in Python.
0:33 So, more advanced topic but they don't actually need to be in Python. You could write a module in Java or a module in JavaScript, or Ruby.
0:39 There's a standard way to call Ansible modules. But for our purposes in the introduction just think about this as Python code
0:45 that Ansible provides you to perform a specific action you want to take. What do we mean by specific action?
0:51 Well, for example, if we want to clone a Git repository. For working on a web application we want to clone it to our development server
0:57 where we're going to do a dev deployment. There is a Git module for handling that task. If we want to enable an operating system's firewall
1:04 and configure various settings on it there's a module for working with firewalls in various operating systems. If we want to send notifications
1:12 let's say, e-mail or text message, or Slack message there are notification modules. The creators and maintainers of the Ansible project
1:19 have done a fantastic job of providing modules for almost any purpose you can think of. And as you can imagine, that's a whole lot of modules.
1:25 So, if we look at the Ansible modules documentation it's listed by category. It can get overwhelming very quickly.
1:32 And as I mentioned, there's notification modules. So, if you click on notification modules in the Ansible documentation
1:38 it's going to list them all out for you. If you're ambitious enough to list all of the modules you will be inundated with everything
1:44 that comes with Ansible. However, I would say this is a really bad place to start. I have never used all of these modules as we scroll through
1:53 we're barely past the modules that come with Ansible that start with C. I strongly recommend against trying to memorize all the modules.
2:00 Instead, throughout the course we'll introduce the most important modules and then you can branch out from there
2:05 depending on how your deployment needs and your configuration management needs require various modules.
2:10 At least you know you can search for all modules on the all modules page. For know, let's say we want to accomplish an action.
2:18 Typically, what I do is go to the specific module. If we want to send a message in Slack/Slack notification we can click on the Slack module
2:26 it'll give us any required parameters and it will give us examples. This is typically where I copy and paste
2:33 start playing with the module that I've never used before and start using it. We'll cover how to use the modules when we go over tasks.
2:38 But I have to commend the Ansible core developers and contributors for all the great documentation that they provide.
2:44 I strongly recommend keeping the documentation up so we know that when we want to accomplish an action in Ansible
2:49 there's a documentation list by category. There is also the code on GitHub. Everything about Ansible is open source
2:55 and reading the source code is really helpful when you're working with modules. So, on GitHub,
3:03 we've got the code for Ansible and you're going to want to look under lib/ansible and this is where the modules directory lies
3:10 and all of the modules underneath. So, when we took a look at the notification modules if we click on notification this is where the source code
3:17 to each one of the modules lives if we look at, we can reference the source code for sending messages to Slack.
3:26 So, we've got Ansible documentation so as we start writing our first playbooks we're going to want to accomplish one or more actions
3:32 we'll use the module's documentation and the module's source code how to use each module properly and philosophically, Ansible modules work well
3:39 because they abstract all the low-level complexity the previous automation systems like Bash Shell scripts and have really hard time of containing.
3:47 One of my first jobs out of college before there were any configuration management systems we used Bash scripts to automate our whole deployment
3:53 and those scripts were littered with conditional statements if we're deploying to dev, take these steps
3:58 if we're deploying to staging, to test, to production for deploying one version or another version Ansible modules work well because
4:04 they abstract that low-level complexity. So we know where to look when we want to use a module but how do we actually use them?
4:10 They are invoked by writing Ansible tasks. So, let's take a look at how to create our tasks.

Talk Python's Mastodon Michael Kennedy's Mastodon