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

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's talk about what servers Ansible knows how to execute your playbooks against. Inventory is a core Ansible concept
0:08 where a file specifies all of the servers that you're going to run your playbook against and it's typically grouped by role.
0:14 There's a default location for the inventory file which is, by convention, named hosts and Ansible will look for that in the Ansible
0:20 subdirectory of the etc system directory. However, I always recommend that you set which inventory file you want to run against with the -i flag.
0:30 The -i flag is useful for two reasons: one, if it can't find your inventory file it'll stop and give you an error message
0:36 so you know you've immediately done something wrong rather than it work off of the default inventory file. That might be the one that you want to use.
0:44 And second, getting comfortable with the -i flag will allow you to use different inventory files for development, staging, local, production
0:52 however many environments that you have. Let's take a look at a playbook example with a single inventory file. We already went over the structure
0:58 of how a playbook would look with our roles directory in group_vars/ and our playbook file deployment.YAML. We would also have a host file.
1:06 And the host file would look something like this. We'd have the name of our roles so we had web server and common as two of our roles.
1:11 And we might have other roles listed as well. We can list out one or more servers. And servers can also be listed many times under different roles.
1:19 So for example, is listed under both web server and common so both web server and common roles will be applied against that server.
1:28 So the Ansible inventory shouldn't feel like a complicated subject. It's really just a list of the servers that we're going to be working with
1:34 explicitly specified in your host file.

Talk Python's Mastodon Michael Kennedy's Mastodon