Among the many configuration management tools available, Ansible has some distinct advantages: It's minimal in nature. You don't need to install anything on your nodes. And it has an easy learning curve. With this updated third edition, you'll quickly learn how to be productive with this tool, whether you're a developer deploying code to production or a system administrator looking for a better automation solution.

Authors Bas Meijer, Lorin Hochstein, and Rene Moser show you how to write playbooks (Ansible's configuration management scripts), manage remote servers, and explore the tool's real power: built-in declarative modules. You'll learn how Ansible has all the functionality you need and the simplicity you desire.

  • Explore Ansible configuration management and deployment
  • Learn how to apply Ansible best practices
  • Understand how to use the new collections format
  • Create a local development environment
  • Generate reusable Ansible content for open source middleware
  • Build container images, images for cloud instances, and cloud computing instances

Ready to use Ansible for mission-critical work? With this new edition, you'll learn how to eliminate the guesswork and assumptions when using software engineering methods to validate code quality.

Table of Contents

  1. 1. Introduction
    1. A Note About Versions
    2. Ansible: What Is It Good For?
    3. How Ansible Works
    4. What’s So Great About Ansible?
    5. Simple
    6. Powerful
    7. Secure
    8. Is Ansible Too Simple?
    9. What Do I Need to Know?
    10. What Isn’t Covered
    11. Installing Ansible
    12. Setting Up a Server for Testing
    13. Using Vagrant to Set Up a Test Server
    14. Telling Ansible About Your Test Server
    15. Simplifying with the ansible.cfg File
    16. Kill your darlings
    17. Moving Forward
  2. 2. Playbooks: A Beginning
    1. Preliminaries
    2. A Very Simple Playbook
    3. Running the Playbook
    4. Playbooks Are YAML
    5. Anatomy of a Playbook
    6. Plays
    7. Did Anything Change? Tracking Host State
    8. Getting Fancier: TLS Support
    9. Conclusion
  3. 3. Inventory: Describing Your Servers
    1. Inventory/Hosts Files
    2. Preliminaries: Multiple Vagrant Machines
    3. Behavioral Inventory Parameters
    4. ansible_connection
    5. ansible_shell_type
    6. ansible_python_interpreter
    7. ansible_*_interpreter
    8. Changing Behavioral Parameter Defaults
    9. Groups and Groups and Groups
    10. Example: Deploying a Django App
    11. Aliases and Ports
    12. Groups of Groups
    13. Numbered Hosts (Pets versus Cattle)
    14. Hosts and Group Variables: Inside the Inventory
    15. Host and Group Variables: In Their Own Files
    16. Dynamic Inventory
    17. Inventory Plugins
    18. Amazon EC2
    19. Azure Resource Manager
    20. The Interface for a Dynamic Inventory Script
    21. Writing a Dynamic Inventory Script
    22. Breaking the Inventory into Multiple Files
    23. Adding Entries at Runtime with add_host and group_by
    24. add_host
    25. group_by
  4. 4. Variables and Facts
    1. Defining Variables in Playbooks
    2. Viewing the Values of Variables
    3. Registering Variables
    4. Facts
    5. Viewing All Facts Associated with a Server
    6. Viewing a Subset of Facts
    7. Any Module Can Return Facts
    8. Local Facts
    9. Using set_fact to Define a New Variable
    10. Built-in Variables
    11. hostvars
    12. inventory_hostname
    13. Groups
    14. Setting Variables on the Command Line
    15. Precedence
  5. 5. Introducing Mezzanine: Our Test Application
    1. Why Is Deploying to Production Complicated?
    2. PostgreSQL: The Database
    3. Gunicorn: The Application Server
    4. Nginx: The Web Server
    5. Supervisor: The Process Manager
  6. 6. Deploying Mezzanine with Ansible
    1. Listing Tasks in a Playbook
    2. Organization of Deployed Files
    3. Variables and Secret Variables
    4. Installing Multiple Packages
    5. Adding the Become Clause to a Task
    6. Updating the Apt Cache
    7. Checking Out the Project Using Git
    8. Installing Mezzanine and Other Packages into a Virtual Environment
    9. Complex Arguments in Tasks: A Brief Digression
    10. Configuring the Database
    11. Generating the local_settings.py File from a Template
    12. Running django-manage Commands
    13. Running Custom Python Scripts in the Context of the Application
    14. Setting Service Configuration Files
    15. Enabling the Nginx Configuration
    16. Installing TLS Certificates
    17. Installing Twitter Cron Job
    18. The Full Playbook
    19. Running the Playbook Against a Vagrant Machine
    20. Troubleshooting
    21. Cannot Check Out Git Repository
    22. Cannot Reach
    23. Bad Request (400)
    24. Deploying Mezzanine on Multiple Machines