Introduction to Ansible Transcripts
Lecture: Why Ansible?
0:00 You may have already set your heart on
0:01 using Ansible, and so you don't really need reasons why.
0:04 But I want to get you even more excited,
0:05 regardless of whether you've decided you're ready
0:07 to use Ansible or you're evaluating alternative choices.
0:10 First off, after years of working in the DevOps space,
0:13 I've found Ansible to be the easiest
0:15 configuration management tool to use.
0:17 I had previously been working with Puppet and Chef,
0:19 and just found that I couldn't keep up with what was
0:22 going on with those tools.
0:23 There is a reason why Ansible exploded in popularity
0:26 once it was released.
0:27 But rather than me just tell you about how easy it is,
0:29 I want to show you a quick example.
0:31 You can get a feel for what you're actually
0:33 going to doing with Ansible.
0:34 I've switched over into my own development environment,
0:37 and I have three windows here.
0:38 The one at the top left has a single Ansible playbook file
0:42 with two tasks in it.
0:43 The right-hand panel is where I've logged into
0:45 a remote server that I've set up on DigitalOcean.
0:48 It's a blank server that has not yet been configured.
0:50 And then on the bottom, we're going to run
0:51 our Ansible playbook.
0:52 First, let's take a look at these two tasks
0:54 on the top left corner.
0:55 Both of these tasks use the same Ansible module.
0:58 Don't worry if terminology like
1:00 playbooks, modules, tasks are unfamiliar.
1:03 We're going to cover all those in depth in Chapter 3
1:05 after you get your own development environment set up.
1:07 For now, just bear with me as you take a look
1:09 at what Ansible is able to do in just a few lines
1:12 of the markup language, YAML, which Ansible uses
1:15 for its playbooks.
1:16 The first task we have here uses the file module,
1:19 and we specify a path.
1:20 We want to create a directory named matt.
1:23 So we specify state of directory and the permissions
1:26 we want for that directory as well.
1:27 What will happen here is that if a directory does not exist,
1:30 home/Matt, it will create one.
1:32 And if not, it'll just let that one be, or it'll change
1:34 its permissions to match the permissions that we want
1:37 on our remote directory.
1:38 The second task uses the same file module,
1:40 but it creates a file named hello-ansible.md for markdown.
1:44 And the state, instead of saying we want a directory,
1:46 we want to use a touch command to create an empty file,
1:48 and we give it some different permissions.
1:49 So the gist here is, we want to create a directory,
1:51 and we want to create a file within that directory.
1:53 If we look over here on the top right where I've logged into
1:55 my remote server, we'll see that no files or directories
1:59 exist under the home directory.
2:00 Let's run our Ansible playbook, and we'll see that
2:02 that quickly changes.
2:04 We're going to run the Ansible playbook command
2:06 with a deploy.yml file.
2:08 We'll specify a private key that is located
2:11 in my .ssh home directory.
2:17 And we'll specify an inventory file which contains the
2:20 IP address for the remote server that we're working with.
2:23 And the de facto standard is to call that
2:25 inventory file hosts.
2:27 We'll kick off our playbook, and Ansible has reported back
2:30 that it was able to execute three tasks.
2:32 First, gathering facts, so gathering all the configuration
2:35 as it exists and then executing the two tasks
2:38 that we specified above in our Ansible playbook.
2:40 Let's see what happened on our remote server.
2:42 We've got our directory named matt now.
2:44 We can go into it, and we see
2:46 we have a hello-ansible.md markdown file.
2:49 So in just a few lines, we were able to modify
2:51 a remote server, and we could actually do that
2:54 with more than a single server.
2:55 We only changed one server here, but we could've run
2:57 the exact same file against thousands of servers.
3:00 And we only used two tasks here.
3:01 Tasks are the building blocks for entire playbooks
3:04 that allow us to set up servers in the exact configurations
3:06 that we want, do our deployments, and handle thousands
3:09 of servers if we want using these maintainable playbooks.
3:11 Throughout this course, you'll become completely comfortable
3:14 with this very simple playbook and building
3:16 much more complicated playbooks for real-world scenarios.
3:19 I've used Ansible on applications ranging from side projects
3:22 that I've built in my spare time
3:24 to really large organizations, where dozens of developers
3:27 are working on the same deployments.
3:28 Ansible's ease of use allows it to scale, both in team size
3:31 and in project size, and across many different projects.
3:34 So what you're learning here, whether it's for
3:35 a side project or for a large organization,
3:37 it'll be relevant in many scenarios.
3:39 Ansible's approach to configuration management is to
3:41 automate what was previously done by hand using Open SSH.
3:45 Other configuration management tools use an agent approach,
3:48 which means that you have to have software running
3:49 on all of your remote machines, and that can create
3:51 an additional attack factor that
3:53 your information security department may say,
3:55 That's not going to happen.
3:56 I gain peace of mind from knowing that Ansible is not
3:58 creating a new paradigm.
3:59 It's taking decades of system administration experience
4:02 and making that much easier, whether you are a sys admin
4:04 or a developer who is trying to deploy
4:06 and configure servers.
4:07 Finally, another huge thing for me is
4:08 I've written playbooks, read them several years later,
4:11 and immediately understood what they were doing.
4:13 I wasn't the biggest fan of YAML when I first saw it,
4:15 but I quickly became comfortable with it.
4:17 And it has major advantages over other markup formats.