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

Implementing DevOps with Ansible 2

Book Description

Leverage the power of Ansible 2 and related tools and scale DevOps processes

About This Book

  • Learn how to use Ansible playbooks along with YAML and JINJA to create efficient DevOps solutions
  • Use Ansible to provision and automate Docker containers and images
  • Learn the fundamentals of Continuous Integration and Continuous Delivery and how to leverage Ansible to implement these modern DevOps
  • Learn the fundamentals of creating custom Ansible modules
  • Learn the fundamentals of Ansible Galaxy
  • Follow along step-by-step as we teach you to scale Ansible for your DevOps processes

Who This Book Is For

If you are a DevOps engineer, administrator, or developer and want to implement the DevOps environment in your organization using Ansible, then this book is for you.

What You Will Learn

  • Get to the grips with the fundamentals of Ansible 2.2 and how you can benefit from leveraging Ansible for DevOps.
  • Adapt the DevOps process and learn how Ansible and other tools can be used to automate it.
  • Start automating Continuous Integration and Continuous Delivery tasks using Ansible
  • Maximize the advantages of tools such as Docker, Jenkins, JIRA, and many more to implement the DevOps culture.
  • Integrate DevOps tools with Ansible
  • Extend Ansible using Python and create custom modules that integrate with unique specific technology stacks
  • Connect and control the states of various third-party applications such as GIT, SVN, Artifactory, Nexus, Jira, Hipchat, Slack, Nginx, and others

In Detail

Thinking about adapting the DevOps culture for your organization using a very simple, yet powerful automation tool, Ansible 2? Then this book is for you!

In this book, you will start with the role of Ansible in the DevOps module, which covers fundamental DevOps practices and how Ansible is leveraged by DevOps organizations to implement consistent and simplified configuration management and deployment. You will then move on to the next module, Ansible with DevOps, where you will understand Ansible fundamentals and how Ansible Playbooks can be used for simple configuration management and deployment tasks. After simpler tasks, you will move on to the third module, Ansible Syntax and Playbook Development, where you will learn advanced configuration management implementations, and use Ansible Vault to secure top-secret information in your organization. In this module, you will also learn about popular DevOps tools and the support that Ansible provides for them (MYSQL, NGINX, APACHE and so on). The last module, Scaling Ansible for the enterprise, is where you will integrate Ansible with CI and CD solutions and provision Docker containers using Ansible.

By the end of the book you will have learned to use Ansible to leverage your DevOps tasks.

Style and approach

A step-by-step guide to automating all DevOps stages with ease using Ansible

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. 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. Downloading the color images of this book
      3. Errata
      4. Piracy
      5. Questions
  2. DevOps Fundamentals
    1. DevOps 101
      1. Culture
      2. Automation
      3. Measurement
      4. Sharing
    2. The History of DevOps
      1. Strides toward the future
    3. DevOps in the Modern Software Organization
      1. The DevOps assembly line
      2. Correlations between a DevOps assembly line and manufacturing
      3. DevOps architectures and practices
      4. Encapsulated software development
      5. Microservices
      6. Continuous Integration and Continuous Delivery
      7. Modularity
      8. Horizontal scalability
      9. Blue-green deployments
      10. Artifact management and versioning
      11. Symmetrical environments
    4. Summary
  3. Configuration Management Essentials
    1. Understanding Configuration Management
    2. Origins of Configuration Management
    3. The Aims of Configuration Management
      1. Scenario 1
      2. Scenario 2
      3. Scenario 3
      4. Scenario 4
    4. Basic Principles of Configuration Management
    5. Configuration Management Best Practices
    6. How Ansible Simplifies DevOps Implementations
    7. Binary Artifact Management and Ansible
    8. Summary
  4. Installing, Configuring, and Running Ansible
    1. Installing Ansible
      1. Red Hat Enterprise Linux via Configuration Management
      2. Apt for Debian/Apt for Ubuntu
      3. Porting Ansible to Gentoo
      4. PKG for FreeBSD
      5. Pip for macOS
      6. OpenCSW for Solaris/SunOS
      7. Via Python pip
      8. Once Ansible has been installed
      9. Setting up authentication between the control server and hosts
    2. The Ansible Architecture
      1. Open source
      2. Module-based
      3. Agentless
      4. Pluggable
      5. Local automation execution using Ansible
      6. Remote automation execution using Ansible
      7. Container-oriented automation
    3. The Ansible Command-Line Interface
      1. Usage: ansible <host-pattern> [options]
      2. Ansible command-line examples
    4. Configuring Ansible
      1. Common base configuration items
    5. The Ansible Inventory
      1. Defined inventory groups
      2. Loose inventory items/hosts/devices
      3. Executing playbook's and targeting specific inventory files and groups
    6. Summary
  5. Playbooks and Inventory Files
    1. Ansible Playbook Constructs
      1. The programming languages that make up a playbook
        1. YAML
        2. Jinja2 – a brief introduction
      2. Constructing an Ansible playbook
        1. Hosts
        2. Variables (vars/vars_files)
        3. Tasks/plays
    2. Ansible Play's and Task's
      1. Ansible plays
      2. Ansible tasks
        1. Multiline task parameters
    3. Variables and Variable Files
      1. Basic variable syntax
      2. Variable files
    4. Hosts and Inventory
    5. Targeting Infrastructure
    6. Ansible Modules
      1. Managing packages in Ansible
        1. Yum
        2. The apt-get and dpkg
      2. Managing users in Ansible
      3. File and directory management in Ansible
      4. Managing services in Ansible
      5. Transferring files in Ansible
    7. Summary
  6. Playbooks – Beyond the Fundamentals
    1. playbook's and Conditional Logic
    2. Iterators and Loops
      1. Basic loops using with_items
      2. Nested loops using with_nested
      3. Looping over hashes using with_dict
      4. Iterating over files using with_file
      5. Iterating over sequential numbers
      6. The do until iterator
      7. Iterating over inventory hosts using play_hosts
    3. Includes
      1. Play-level includes
      2. Task-level includes
      3. Dynamic includes
    4. Ansible Roles
    5. Ansible Register Variables
      1. Simple Ansible registers
      2. Accessing registers
      3. Additional conditional logic with registers
        1. Null or empty comparisons
        2. Vars and Ansible registers
        3. Iterating over register contents
    6. Ansible Handlers
    7. Summary
  7. Jinja in Ansible
    1. Introducing Jinja
    2. Jinja2 Programming Constructs
      1. Expressions, filters, and variables
        1. Jinja string concatenation and manipulation
        2. Basic arithmetic operations in Jinja
        3. Compound math equations and order of operations in Jinja
        4. Filters available
      2. Conditional logic (if-then-else)
      3. Loops and iterators
        1. Simple counters
        2. List iterators
        3. Complex iterators using Jinja
    3. Applying Jinja in Ansible Playbook's
    4. Summary
  8. Ansible Vault
    1. The Ansible Vault Architecture
    2. Basic Vault Usage
      1. Encrypting an Ansible vault YAML file
      2. To decrypt
      3. To rekey an Ansible vault file
      4. Editing in place
      5. Decrypting the vault when running a playbook
        1. Automatically decrypting using password files
        2. Manually decrypting vault data
    3. Real-world Ansible Vault Workflow
      1. Ansible vault with roles
    4. Summary
  9. Ansible Modules and Libraries
    1. Introducing Ansible Modules
    2. Integrating Ansible with Other Technologies
      1. Ansible with JIRA
      2. Ansible and Git
      3. Ansible and Jenkins
      4. Ansible and Docker
    3. Summary
  10. Integrating Ansible with CI and CD Solutions
    1. Overview of Continuous Integration
      1. Continuous integration concepts and practices
      2. Handling unfinished work
        1. Branch by abstraction
        2. Feature toggles
        3. A/B testing patterns
    2. Overview of Continuous Delivery
      1. Continuous Delivery defined
      2. Handling complex and long running builds and deployments
      3. CI->CD feedback loop
      4. Blue-green deployments
        1. CI->CD anti-patterns
    3. Ansible's Role in CI->CD
      1. Ansible best practices in CI->CD
    4. Integrating Ansible with Jenkins
      1. The Jenkins Ansible plugin
      2. The Jenkins Ansible API modules
        1. The jenkins_job Ansible Module
    5. Integrating Ansible with Vagrant
      1. Leveraging Ansible for Vagrant provisioning
    6. Summary
  11. Ansible and Docker
    1. Understanding Docker's Architecture
      1. Understanding Docker containers as environments
    2. Managing Docker Containers with Ansible
      1. Creating Docker containers
      2. Removing Docker containers
      3. Launching and stopping Docker containers
      4. Managing network access Docker containers
    3. Using Ansible to Create Docker Images
      1. Using Dockerfiles to launch Ansible playbooks
    4. Managing Docker Images with Ansible
      1. Pulling, pushing, and tagging images
      2. Building and archiving Docker images
        1. Saving and loading archived Docker images
    5. Gathering Facts About Docker Containers
    6. Summary
  12. Extending Ansible
    1. Understanding Ansible Plugins and its Architecture
      1. When should we create a module?
    2. Setting Up the Ansible Module Development Environment
      1. Ansible module testing tool setup
    3. Developing Hello World Ansible Module
      1. Testing a developmental Ansible module
      2. Reading input parameters
      3. Adding custom facts to a module
    4. Setting up the Ansible Plugin Development Environment
    5. Understanding the Different Types of Plugins
      1. Action plugins
      2. Callback plugins
      3. Connection plugins
      4. Lookup plugins
      5. Distributing Ansible plugins
    6. Summary
  13. Ansible Galaxy
    1. Ansible Galaxy Fundamentals
      1. The Ansible Galaxy website
      2. The Ansible Galaxy command-line interface
        1. Ansible Galaxy command-line options explained
          1. The install subcommand
          2. The delete subcommand
          3. The import subcommand
          4. The ifo subcommand
          5. The init command
          6. The list subcommand
          7. The login subcommand
          8. The remove subcommand
          9. The search subcommand
          10. The setup subcommand
          11. The help command
    2. Summary