Introduction to Ansible Transcripts
Chapter: Running Playbooks
Lecture: YAML in the Playbook File
0:00 Now that we're ready to write our Playbook
0:01 switch over into your development environment.
0:03 I'll be writing this code on Ubuntu 18.04.
0:06 If you're working on a Mac
0:07 you should be able to follow along
0:08 with the same commands.
0:09 And again, unfortunately on Windows, Ansible is not set up
0:12 to run on Windows as a command machine.
0:14 You can control Windows machines from Ansible
0:16 but executing Ansible Playbooks
0:18 really doesn't work even for basic purposes on Windows.
0:21 First thing we're going to want to do
0:22 is create a directory for our first Playbook.
0:25 Switch into that directory
0:27 and, of course, it'll be empty.
0:28 We need to write a first YAML file.
0:32 Throughout these videos, I'm going to be using Vim
0:34 but if you're more comfortable in Sublime Text
0:35 or another editor, feel free to use that instead.
0:38 Start out with a little note
0:39 and you can put whatever comments to yourself
0:40 that'll help you remember what this file is for.
0:42 It just is, these are high-level instructions
0:44 that tell Ansible which tasks to apply to which hosts.
0:51 Now we're going to write some YAML.
0:59 This YAML instructs Ansible to take every host
1:02 in the inventory file that we'll write.
1:05 We're going to use the root user
1:06 which, typically, we would not do
1:07 when we configure a server.
1:09 We'll learn how to lock down a server later.
1:10 But, for simplicity's sake
1:11 we're going to use the root user
1:13 on the server that we provision.
1:15 We're only going to have a single role
1:17 and that will be common.
1:18 So what we've said here in this Playbook
1:20 with high-level instructions, take every host
1:22 we're only going to have a single host
1:23 on that hose, use the root user
1:25 and apply the common role to all those hosts.
1:27 Here's how we know which host to apply it to.
1:29 Create a host file.
1:32 In the host file, specify the role named common.
1:37 Now we need to say which server we're going to apply this to.
1:40 And we need the IP address, but we don't have a server yet.
1:43 So let's go to DigitalOcean and provision a server
1:45 and then we'll know what to put in here.