O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Learning Ansible

Book Description

Use Ansible to configure your systems, deploy software, and orchestrate advanced IT tasks

In Detail

Automation includes provisioning new servers, making sure the servers adhere to their role and maintain the desired state from a configuration perspective, and orchestrating various actions across environments and deploying code as expected to all these servers. This is where Ansible steps in. It is secure, highly reliable, and minimalistic in nature. It automates configuration management, application deployment, and many other IT needs.

Learning Ansible will equip you with the necessary skills to automate/improve your infrastructure from a configuration management perspective. You will also be able to use Ansible for one-click deployments, provisioning, and orchestrating your infrastructure.

What You Will Learn

  • Set up and write basic playbooks, with more focus on configuration management
  • Develop and test Ansible playbooks
  • Use Ansible to handle errors, add callbacks, and rollback playbooks
  • Write custom modules and test them
  • Use Ansible modules to provision servers on various clouds
  • Deploy and orchestrate your Ansible infrastructure

Table of Contents

  1. Learning Ansible
    1. Table of Contents
    2. Learning Ansible
    3. Credits
    4. About the Authors
    5. Acknowledgments
    6. About the Reviewers
    7. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    8. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    9. 1. Getting Started with Ansible
      1. What is Ansible?
        1. Installing Ansible
          1. Installing Ansible from source
          2. Installing Ansible using the system's package manager
            1. Installing via Yum
            2. Installing via Apt
            3. Installing via Homebrew
            4. Installing via pip
        2. Hello Ansible
      2. The Ansible architecture
      3. Configuring Ansible
        1. Configuration using environment variables
        2. Configuration using ansible.cfg
      4. Configuration management
      5. Working with playbooks
        1. The anatomy of a playbook
      6. Variables and their types
        1. Variable names
          1. Valid variable names in Ansible
          2. Invalid variable names in Ansible
        2. Variables in an included task file
        3. Variables in a playbook
        4. Variables in a global file
        5. Facts as variables
        6. Command-line variables
        7. Variables in an inventory file
      7. Working with inventory files
        1. The basic inventory file
        2. Groups in an inventory file
        3. Groups of groups
        4. Regular expressions with an inventory file
          1. External variables
          2. Host variables
          3. Group variables
          4. Variable files
        5. Overriding configuration parameters with an inventory file
      8. Working with modules
        1. Command modules
          1. The command module
          2. The raw module
          3. The script module
          4. The shell module
        2. File modules
          1. The file module
          2. Debugging in Ansible
          3. The template module
          4. The copy module
        3. The source control module – git
      9. Summary
    10. 2. Developing, Testing, and Releasing Playbooks
      1. Managing source code – Git
      2. Developing a playbook
        1. Installing VirtualBox and Vagrant
        2. Downloading the Vagrant box
        3. Developing a machine
        4. Provisioning in Vagrant using an Ansible provisioner
      3. Testing a playbook
        1. Using the --syntax-check option
        2. The check mode
        3. Indicating differences between files using --diff
      4. Functional testing in Ansible
        1. Functional testing using Assert
        2. Testing with tags
          1. The --skip-tags
            1. Using the install, start, and stop tags
      5. The Serverspec tool
        1. Installing Serverspec
        2. Analyzing the Rakefile and running tests
        3. Running playbook_tester
      6. Handling environments
        1. Code based on Git branch
        2. A single stable branch with multiple folders
      7. Summary
    11. 3. Taking Ansible to Production
      1. Working with the local_action feature
      2. Working with conditionals
      3. Working with loops
        1. Standard loops
        2. Nested Loops
        3. Looping over subelements
      4. Working with include
      5. Working with handlers
      6. Working with roles
        1. The Cassandra role
        2. Creating a task file with roles
        3. Using handlers with roles
      7. The Ansible template – Jinja filters
        1. Formatting data using filters
        2. Using filters with conditionals
        3. Defaulting undefined variables
      8. Security Management
        1. Using Ansible Vault
        2. Encrypting user passwords
        3. Hiding passwords
        4. Using no_log
      9. Summary
    12. 4. Error Handling, Rollback, and Reporting
      1. Error handling and Rollback
        1. Executing the playbook
      2. Callback plugins
      3. Monitoring and alerting
        1. E-mails
        2. HipChat
        3. Nagios
        4. Graphite
          1. Time for an error
      4. Summary
    13. 5. Working with Custom Modules
      1. Using Python modules
        1. Working with exit_json and fail_json
        2. Testing Python modules
      2. Using Bash modules
      3. Using Ruby modules
      4. Testing modules
      5. Summary
    14. 6. Provisioning
      1. Provisioning a machine in the cloud
        1. Diving deep into the playbook
        2. Launching a DigitalOcean instance
      2. Docker provisioning
        1. Installing Docker on hosts
        2. Deploying new Docker images
        3. Building or provisioning new Docker images
      3. Dynamic Inventory
      4. Summary
    15. 7. Deployment and Orchestration
      1. Deploying a sample Ruby on Rails application
      2. Packaging
        1. Deployment strategies with RPM
          1. Deploying newer versions of RPM in the same directory
          2. Deploying the RPM in a version-specific directory
      3. Canary deployment
      4. Orchestration of a Tomcat deployment
      5. Deploying Ansible pull
      6. Summary
    16. A. Ansible on Windows, Ansible Galaxy, and Ansible Tower
      1. Ansible on Windows
      2. Ansible Galaxy
      3. Ansible Tower
    17. Index