Skip to Content
Ansible: Up and Running, 3rd Edition
book

Ansible: Up and Running, 3rd Edition

by Bas Meijer, Lorin Hochstein, René Moser
July 2022
Intermediate to advanced
470 pages
10h 22m
English
O'Reilly Media, Inc.
Book available
Content preview from Ansible: Up and Running, 3rd Edition

Chapter 3. Playbooks: A Beginning

When you start using Ansible, one of the first things you’ll do is begin writing playbooks. Playbook is the term that Ansible uses for a configuration management script. Let’s look at an example: here is a playbook for installing the NGINX web server and configuring it for secure communication.

If you follow along in this chapter, you should end up with the directory tree listed here:

.
├── Vagrantfile
├── ansible.cfg
├── files
│   ├── index.html
│   ├── nginx.conf
│   ├── nginx.crt
│   └── nginx.key
├── inventory
│   └── vagrant.ini
├── requirements.txt
├── templates
│   ├── index.html.j2
│   └── nginx.conf.j2
├── webservers-tls.yml
├── webservers.yml
└── webservers2.yml

Preliminaries

Modify your Vagrantfile so it looks like this:

Vagrant.configure(2) do |config|
  config.vm.box = "ubuntu/focal64"
  config.vm.hostname = "testserver"
  config.vm.network "forwarded_port",
    id: 'ssh', guest: 22, host: 2202, host_ip: "127.0.0.1", auto_correct: false
  config.vm.network "forwarded_port",
    id: 'http', guest: 80, host: 8080, host_ip: "127.0.0.1"
  config.vm.network "forwarded_port",
    id: 'https', guest: 443, host: 8443, host_ip: "127.0.0.1"
  # disable updating guest additions
  if Vagrant.has_plugin?("vagrant-vbguest")
    config.vbguest.auto_update = false
  end
  config.vm.provider "virtualbox" do |virtualbox|
    virtualbox.name = "ch03"
  end
end

This maps port 8080 on your local machine to port 80 of the Vagrant machine, and port 8443 on your local machine to port 443 on ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Kubernetes: Up and Running, 3rd Edition

Kubernetes: Up and Running, 3rd Edition

Brendan Burns, Joe Beda, Kelsey Hightower, Lachlan Evenson
Dive Into Ansible - From Beginner to Expert in Ansible

Dive Into Ansible - From Beginner to Expert in Ansible

James Spurin - Docker Captain, CNCF Ambassador, and Kubestronaut
Docker: Up & Running, 3rd Edition

Docker: Up & Running, 3rd Edition

Sean P. Kane, Karl Matthias

Publisher Resources

ISBN: 9781098109141Errata PageSupplemental Content