0%

Book Description

Leverage the power of Ansible to gain complete control over your systems and automate application deployment

Key Features

  • Use Ansible 2.9 to automate and control your infrastructure
  • Delve into advanced functionality such as plugins and custom modules in Ansible
  • Automate and orchestrate major cloud platforms such as OpenStack, AWS, and Azure using Ansible

Book Description

Ansible enables you to automate software provisioning, configuration management, and application roll-outs, and can be used as a deployment and orchestration tool. While Ansible provides simple yet powerful features to automate multi-layer environments using agentless communication, it can also solve other critical IT challenges, such as ensuring continuous integration and continuous deployment (CI/CD) with zero downtime.

In this book, you'll work with Ansible 2.9 and learn to solve complex issues quickly with the help of task-oriented scenarios. You'll start by installing and configuring Ansible on Linux and macOS to automate monotonous and repetitive IT tasks and get to grips with concepts such as playbooks, inventories, and network modules. As you progress, you'll gain insight into the YAML syntax and learn how to port between Ansible versions. In addition to this, you'll also understand how Ansible enables you to orchestrate multi-layer environments such as networks, containers, and the cloud.

By the end of this Ansible book, you'll be well - versed in writing playbooks and other related Ansible code to overcome just about all of your IT challenges, from infrastructure-as-code provisioning to application deployments, and even handling the mundane day-to-day maintenance tasks that take up so much valuable time.

What you will learn

  • Become familiar with the fundamentals of the Ansible framework
  • Set up role-based variables and dependencies
  • Avoid common mistakes and pitfalls when writing automation code in Ansible
  • Extend Ansible by developing your own modules and plugins
  • Contribute to the Ansible project by submitting your own code
  • Follow best practices for working with cloud environment inventories
  • Troubleshoot issues triggered during Ansible playbook runs

Who this book is for

If you are a DevOps engineer, administrator, or any IT professional looking to automate IT tasks using Ansible, this book is for you. Prior knowledge of Ansible is not necessary.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Practical Ansible 2
  3. About Packt
    1. Why subscribe?
  4. Contributors
    1. About the authors
    2. About the reviewers
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  6. Section 1: Learning the Fundamentals of Ansible
  7. Getting Started with Ansible
    1. Technical requirements
    2. Installing and configuring Ansible
      1. Installing Ansible on Linux and FreeBSD
      2. Installing Ansible on macOS
      3. Configuring Windows hosts for Ansible
    3. Understanding your Ansible installation
      1. Understanding how Ansible connects to hosts
      2. Verifying the Ansible installation
      3. Managed node requirements
    4. Running from source versus pre-built RPMs
    5. Summary
    6. Questions
    7. Further reading
  8. Understanding the Fundamentals of Ansible
    1. Technical requirements
    2. Getting familiar with the Ansible framework
      1. Breaking down the Ansible components
      2. Learning the YAML syntax
      3. Organizing your automation code
    3. Exploring the configuration file
    4. Command-line arguments
      1. Understanding ad hoc commands
    5. Defining variables
    6. Understanding Jinja2 filters
    7. Summary
    8. Questions
    9. Further reading
  9. Defining Your Inventory
    1. Technical requirements
    2. Creating an inventory file and adding hosts
      1. Using host groups
      2. Adding host and group variables to your inventory
    3. Generating a dynamic inventory file 
      1. Using multiple inventory sources in the inventory directories
      2. Using static groups with dynamic groups
    4. Special host management using patterns
    5. Summary
    6. Questions
    7. Further reading
  10. Playbooks and Roles
    1. Technical requirements
    2. Understanding the playbook framework
      1. Comparing playbooks and ad hoc tasks
      2. Defining plays and tasks
    3. Understanding roles – the playbook organizer
      1. Setting up role-based variables and dependencies
      2. Ansible Galaxy
    4. Using conditions in your code
    5. Repeating tasks with loops
    6. Grouping tasks using blocks
    7. Configuring play execution via strategies
    8. Using ansible-pull
    9. Summary
    10. Questions
    11. Further reading
  11. Section 2: Expanding the Capabilities of Ansible
  12. Consuming and Creating Modules
    1. Technical requirements
    2. Executing multiple modules using the command line
    3. Reviewing the module index
    4. Accessing module documentation from the command line
    5. Module return values
    6. Developing custom modules
      1. Avoiding common pitfalls
      2. Testing and documenting your module
      3. The module checklist
      4. Contributing upstream – submitting a GitHub pull request
    7. Summary
    8. Questions
    9. Further reading
  13. Consuming and Creating Plugins
    1. Technical requirements
    2. Discovering the plugin types
    3. Finding included plugins
    4. Creating custom plugins
      1. Learning to integrate custom plugins with Ansible source code
      2. Sharing plugins with the community
    5. Summary
    6. Questions
    7. Further reading
  14. Coding Best Practices
    1. Technical requirements
    2. The preferred directory layout
    3. The best approach to cloud inventories
    4. Differentiating between different environment types
    5. The proper approach to defining group and host variables
    6. Using top-level playbooks
    7. Leveraging version control tools 
    8. Setting OS and distribution variances
    9. Porting between Ansible versions 
    10. Summary
    11. Questions
    12. Further reading
  15. Advanced Ansible Topics
    1. Technical requirements
    2. Asynchronous versus synchronous actions
    3. Control play execution for rolling updates
    4. Configuring the maximum failure percentage
    5. Setting task execution delegation
    6. Using the run_once option
    7. Running playbooks locally
    8. Working with proxies and jump hosts
    9. Configuring playbook prompts
    10. Placing tags in the plays and tasks
    11. Securing data with Ansible Vault
    12. Summary
    13. Questions
    14. Further reading
  16. Section 3: Using Ansible in an Enterprise
  17. Network Automation with Ansible
    1. Technical requirements
    2. Why automate network management?
    3. Learning how Ansible manages networking devices
      1. Enabling network automation
      2. Reviewing the available Ansible networking modules
    4. Connecting to network devices
      1. Environment variables for network devices
    5. Conditional statements for networking devices
    6. Summary
    7. Questions
    8. Further reading
  18. Container and Cloud Management
    1. Technical requirements
    2. Designing and building containers with playbooks
    3. Managing multiple container platforms
      1. Deploying to Kubernetes with ansible-container
      2. Managing Kubernetes objects with Ansible
        1. Installing Ansible Kubernetes dependencies
        2. Listing Kubernetes namespaces with Ansible
        3. Creating a Kubernetes namespace with Ansible
        4. Creating a Kubernetes Service with Ansible
    4. Automating Docker with Ansible
    5. Exploring container-focused modules
    6. Automating against Amazon Web Services
      1. Installation
      2. Authentication
      3. Creating your first machine
    7. Complementing Google Cloud Platform with automation
      1. Installation
      2. Authentication
      3. Creating your first machine
    8. Seamless automation integration to Azure
      1. Installation
      2. Authentication
      3. Creating your first machine
    9. Expanding your environment with Rackspace Cloud
      1. Installation
      2. Authentication
      3. Creating your first machine
    10. Using Ansible to orchestrate OpenStack
      1. Installation
      2. Authentication
      3. Creating your first machine
    11. Summary
    12. Questions
    13. Further reading
  19. Troubleshooting and Testing Strategies
    1. Technical requirements
    2. Digging into playbook execution problems
    3. Using host facts to diagnose failures
    4. Testing with a playbook
      1. Using check mode
    5. Solving host connection issues
    6. Passing working variables via the CLI
      1. Limiting the host's execution
    7. Flushing the code cache
    8. Checking for bad syntax
    9. Summary
    10. Questions
    11. Further reading
  20. Getting Started with Ansible Tower
    1. Technical requirements
    2. Installing AWX
    3. Running your first playbook from AWX
      1. Creating an AWX project
      2. Creating an inventory
      3. Creating a job template
      4. Running a job
    4. Controlling access to AWX
      1. Creating a user
      2. Creating a team
      3. Creating an organization
      4. Assigning permissions in AWX
    5. Summary
    6. Questions
  21. Assessments
    1. Chapter 1
    2. Chapter 2
    3. Chapter 3
    4. Chapter 4
    5. Chapter 5
    6. Chapter 6
    7. Chapter 7
    8. Chapter 8
    9. Chapter 9
    10. Chapter 10
    11. Chapter 11
    12. Chapter 12
  22. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think
52.205.159.48