Introduction to Ansible Transcripts
Chapter: Ansible Core Concepts
0:00 Let's talk about what servers Ansible knows
0:02 how to execute your playbooks against.
0:04 Inventory is a core Ansible concept
0:07 where a file specifies all of the servers
0:09 that you're going to run your playbook against
0:11 and it's typically grouped by role.
0:13 There's a default location for the inventory file
0:15 which is, by convention, named hosts
0:18 and Ansible will look for that in the Ansible
0:19 subdirectory of the etc system directory.
0:22 However, I always recommend that you set
0:24 which inventory file you want to run against
0:27 with the -i flag.
0:29 The -i flag is useful for two reasons:
0:31 one, if it can't find your inventory file
0:34 it'll stop and give you an error message
0:35 so you know you've immediately done something wrong
0:37 rather than it work off of the default inventory file.
0:41 That might be the one that you want to use.
0:43 And second, getting comfortable with the -i flag
0:46 will allow you to use different inventory files
0:48 for development, staging, local, production
0:51 however many environments that you have.
0:53 Let's take a look at a playbook example
0:54 with a single inventory file.
0:56 We already went over the structure
0:57 of how a playbook would look
0:59 with our roles directory in group_vars/
1:01 and our playbook file deployment.YAML.
1:03 We would also have a host file.
1:05 And the host file would look something like this.
1:06 We'd have the name of our roles
1:08 so we had web server and common as two of our roles.
1:10 And we might have other roles listed as well.
1:12 We can list out one or more servers.
1:14 And servers can also be listed
1:16 many times under different roles.
1:18 So for example, 192.168.1.1 is listed
1:22 under both web server and common
1:23 so both web server and common roles
1:25 will be applied against that server.
1:27 So the Ansible inventory shouldn't feel
1:28 like a complicated subject.
1:30 It's really just a list of the servers
1:32 that we're going to be working with
1:33 explicitly specified in your host file.