Ansible for DevOps cover page
Ansible for DevOps

Ansible for DevOps

Server and configuration management for humans


Ansible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
Ansible for DevOps Edit
This book is 95% Complete

Updated

  • $14.99

    Minimum

  • $19.99

    Suggested

Bundles

Vagrant CookBook
Ansible for DevOps

Vagrant Ansible

  • $34.98

    Regular Price

  • $26.99

    Bundle Price

2 Books

Learn more
Ansible for DevOps
Ansible for AWS

Ansible Bundle

  • $44.98

    Regular Price

  • $44.99

    Bundle Price

2 Books

Learn more
Ansible for DevOps
Servers for Hackers

Automated Servers

  • $49.98

    Regular Price

  • $44.99

    Bundle Price

2 Books

Learn more

About the Book

Ansible is a simple, but powerful, server and configuration management tool (with a few other tricks up its sleeve). This book will help those familiar with the command line and basic shell scripting start using Ansible to provision and manage anywhere from one to thousands of servers.

The book begins with fundamentals, like installing Ansible, setting up a basic inventory file, and basic concepts, then guides you through Ansible's many uses, including ad-hoc commands, basic and advanced playbooks, application deployments, custom modules, and special cases like running ansible in 'pull' mode when you have thousands of servers to manage (or more). Everything is explained with pertinent real-world examples, often using Vagrant-managed virtual machines.

As this is a work-in-progress, community feedback and suggestions will be taken into account as to what topics will be covered, and with how much depth they will be covered.

Examples in the book are tested with the latest version of Ansible (1.9.x as of this writing).

Read More

Table of Contents

  • Preface
    • Who is this book for?
    • Typographic conventions
    • Please help improve this book!
    • About the Author
  • Introduction
    • In the beginning, there were sysadmins
    • Modern infrastructure management
    • Ansible and Ansible, Inc.
    • Ansible Examples
    • Other resources
  • Chapter 1 - Getting Started with Ansible
    • Ansible and Infrastructure Management
      • On snowflakes and shell scripts
      • Configuration management
    • Installing Ansible
    • Creating a basic inventory file
    • Running your first Ad-Hoc Ansible command
    • Summary
  • Chapter 2 - Local Infrastructure Development: Ansible and Vagrant
    • Prototyping and testing with local virtual machines
    • Your first local server: Setting up Vagrant
    • Using Ansible with Vagrant
    • Your first Ansible playbook
    • Summary
  • Chapter 3 - Ad-Hoc Commands
    • Conducting an orchestra
    • Build infrastructure with Vagrant for testing
    • Inventory file for multiple servers
    • Your first ad-hoc commands
      • Discover Ansible’s parallel nature
      • Learning about your environment
      • Make changes using Ansible modules
    • Configure groups of servers, or individual servers
      • Configure the Application servers
      • Configure the Database servers
      • Make changes to just one server
    • Manage users and groups
    • Manage files and directories
      • Get information about a file
      • Copy a file to the servers
      • Retrieve a file from the servers
      • Create directories and files
      • Delete directories and files
    • Run operations in the background
      • Update servers asynchronously, monitoring progress
      • Fire-and-forget tasks
    • Check log files
    • Manage cron jobs
    • Deploy a version-controlled application
    • Ansible’s SSH connection history
      • Paramiko
      • OpenSSH (default)
      • Accelerated Mode
      • Faster OpenSSH in Ansible 1.5+
    • Summary
  • Chapter 4 - Ansible Playbooks
    • Power plays
    • Running Playbooks with ansible-playbook
      • Limiting playbooks to particular hosts and groups
      • Setting user and sudo options with ansible-playbook
      • Other options for ansible-playbook
    • Real-world playbook: CentOS Node.js app server
      • Add extra repositories
      • Deploy a Node.js app
      • Launch a Node.js app
      • Node.js app server summary
    • Real-world playbook: Ubuntu LAMP server with Drupal
      • Include a variables file, and discover pre_tasks and handlers
      • Basic LAMP server setup
      • Configure Apache
      • Configure PHP with lineinfile
      • Configure MySQL
      • Install Composer and Drush
      • Install Drupal with Git and Drush
      • Drupal LAMP server summary
    • Real-world playbook: Ubuntu Apache Tomcat server with Solr
      • Include a variables file, and discover pre_tasks and handlers
      • Install Apache Tomcat 7
      • Install Apache Solr
      • Apache Solr server summary
    • Summary
  • Chapter 5 - Ansible Playbooks - Beyond the Basics
    • Handlers
    • Environment variables
      • Per-play environment variables
    • Variables
      • Playbook Variables
      • Inventory variables
      • Registered Variables
      • Accessing Variables
      • Host and Group variables
        • group_vars and host_vars
        • Magic variables with host and group variables and information
      • Facts (Variables derived from system information)
        • Local Facts (Facts.d)
      • Variable Precedence
    • If/then/when - Conditionals
      • Jinja2 Expressions, Python built-ins, and Logic
      • register
      • when
      • changed_when and failed_when
      • ignore_errors
    • Delegation, Local Actions, and Pauses
      • Pausing playbook execution with wait_for
      • Running an entire playbook locally
    • Prompts
    • Tags
    • Summary
  • Chapter 6 - Playbook Organization - Roles and Includes
    • Includes
      • Handler includes
      • Playbook includes
      • Complete includes example
    • Roles
      • Role scaffolding
      • Building your first role
      • More flexibility with role vars and defaults
      • Other role parts: handlers, files, and templates
        • Handlers
        • Files and Templates
      • Organizing more complex and cross-platform roles
    • Ansible Galaxy
      • Getting roles from Galaxy
        • Using role requirements files to manage dependencies
      • A LAMP server in six lines of YAML
      • A Solr server in six lines of YAML
      • Helpful Galaxy commands
      • Contributing to Ansible Galaxy
    • Summary
  • Chapter 7 - Inventories
    • A real-world web application server inventory
      • Non-prod environments, separate inventory files
    • Inventory variables
      • host_vars
      • group_vars
    • Ephemeral infrastructure: Dynamic inventory
      • Dynamic inventory with DigitalOcean
        • DigitalOcean account prerequisites
        • Connecting to your DigitalOcean account
        • Creating a droplet with Ansible
        • DigitalOcean dynamic inventory with digital_ocean.py
      • Dynamic inventory with AWS
      • Inventory on-the-fly: add_host and group_by
      • Multiple inventory sources - mixing static and dynamic inventories
      • Creating custom dynamic inventories
    • Summary
  • Chapter 8 - Ansible Cookbooks
    • Highly-Available Infrastructure with Ansible
      • Directory Structure
      • Individual Server Playbooks
      • Main Playbook for Configuring All Servers
      • Getting the required roles
      • Vagrantfile for Local Infrastructure via VirtualBox
      • Provisioner Configuration: DigitalOcean
      • Provisioner Configuration: Amazon Web Services (EC2)
      • Summary
    • ELK Logging with Ansible
      • ELK Playbook
      • Forwarding Logs from Other Servers
      • Summary
    • GlusterFS Distributed File System Configuration with Ansible
      • Configuring Gluster - Basic Overview
      • Configuring Gluster with Ansible
      • Summary
    • Mac Provisioning with Ansible and Homebrew
      • Running Ansible playbooks locally
      • Automating Homebrew package and app management
      • Configuring Mac OS X through dotfiles
      • Summary
    • Docker-based Infrastructure with Ansible
      • A brief introduction to Docker containers
      • Using Ansible to build and manage containers
      • Building a Flask app with Ansible and Docker
        • Data storage container
        • Flask container
        • MySQL container
      • Ship it!
      • Summary
  • Chapter 9 - Deployments with Ansible
    • Deployment strategies
    • Simple single-server deployments
      • Provisioning a simple Ruby on Rails server
      • Deploying a Rails app to the server
      • Provisioning and Deploying the Rails App
      • Deploying application updates
    • Zero-downtime multi-server deployments
      • Ensuring zero downtime with serial and integration tests
      • Deploying to app servers behind a load balancer
    • Capistrano-style and blue-green deployments
    • Additional Deployment Scenarios
    • Summary
  • Chapter 10 - Server Security and Ansible
    • A brief history of SSH and remote access
      • Telnet
      • rlogin, rsh and rcp
      • SSH
      • The evolution of SSH and the future of remote access
    • Use secure and encrypted communication
    • Disable root login and use sudo
    • Remove unused software, open only required ports
    • Use the principle of least privilege
      • User account configuration
      • File permissions
    • Update the OS and installed software
      • Automating updates
      • Automating updates for RedHat-based systems
      • Automating updates for Debian-based systems
    • Use a properly-configured firewall
      • Configuring a firewall with ufw on Debian or Ubuntu
      • Configuring a firewall with firewalld on RedHat, Fedora, or CentOS
    • Make sure log files are populated and rotated
    • Monitor logins and block suspect IP addresses
    • Use SELinux (Security-Enhanced Linux) or AppArmor
    • Summary and further reading
  • Chapter 11 - Automating Your Automation - Ansible Tower and CI/CD
    • Ansible Tower
      • Getting and Installing Ansible Tower
      • Using Ansible Tower
      • Other Tower Features of Note
      • Tower Alternatives
    • Jenkins CI
      • Build a local Jenkins server with Ansible
      • Create an Ansible playbook on the Jenkins server
      • Create a Jenkins job to run an Ansible Playbook
    • Unit, Integration, and Functional Testing
      • Debugging and Asserting
        • The debug module
        • The fail and assert modules
      • Checking syntax and performing dry runs
      • Automated testing on GitHub using Travis CI
        • Setting up a role for testing
        • Testing the role’s syntax
        • Role success - first run
        • Role idempotence
        • Role success - final result
        • Some notes about Travis CI
        • Real-world examples
      • Automated testing with test-runner
      • Functional testing using serverspec
    • Summary
  • Appendix A - Using Ansible on Windows workstations
    • Prerequisites
    • Set up an Ubuntu Linux Virtual Machine
    • Log into the Virtual Machine
    • Install Ansible
    • Summary
  • Appendix B - Ansible Best Practices and Conventions
    • Playbook Organization
      • Write comments and use name liberally
      • Include related variables and tasks
      • Use Roles to bundle logical groupings of configuration
      • Use role defaults and vars correctly
    • YAML Conventions and Best Practices
      • YAML for Ansible tasks
      • Three ways to format Ansible tasks
        • Shorthand/one-line (key=value)
        • Structured map/multi-line (key:value)
        • Folded scalars/multi-line (>)
      • Using | to format multiline variables
    • Using ansible-playbook
    • Use Ansible Tower
    • Specify --forks for playbooks running on > 5 servers
    • Use Ansible’s Configuration file
    • Summary
  • Changelog
    • Version 0.95 (2015-05-26)
    • Version 0.94 (2015-05-16)
    • Version 0.92 (2015-04-09)
    • Version 0.90 (2015-03-16)
    • Version 0.89 (2015-02-26)
    • Version 0.88 (2015-02-13)
    • Version 0.87 (2015-02-01)
    • Version 0.84 (2015-01-27)
    • Version 0.81 (2015-01-11)
    • Version 0.75 (2014-12-23)
    • Version 0.73 (2014-12-09)
    • Version 0.71 (2014-11-27)
    • Version 0.70 (2014-11-16)
    • Version 0.64 (2014-10-24)
    • Version 0.62 (2014-10-07)
    • Version 0.60 (2014-09-30)
    • Version 0.58 (2014-08-01)
    • Version 0.56 (2014-07-20)
    • Version 0.54 (2014-07-02)
    • Version 0.53 (2014-06-28)
    • Version 0.52 (2014-06-14)
    • Version 0.50 (2014-05-05)
    • Version 0.49 (2014-04-24)
    • Version 0.47 (2014-04-13)
    • Version 0.44 (2014-04-04)
    • Version 0.42 (2014-03-25)
    • Version 0.38 (2014-03-11)
    • Version 0.35 (2014-02-25)
    • Version 0.33 (2014-02-20)

Read More

About the Author

The Leanpub Unconditional, No Risk, 100% Happiness Guarantee

Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks. We process the refunds manually, so they may take a few days to show up.
See full terms