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

Learn Ansible

Book Description

Run Ansible playbooks to launch complex multi-tier applications hosted in public clouds

About This Book
  • Build your learning curve using Ansible
  • Automate cloud, network, and security infrastructures with ease
  • Gain hands-on exposure on Ansible
Who This Book Is For

Learn Ansible is perfect for system administrators and developers who want to take their current workflows and transform them into repeatable playbooks using Ansible. No prior knowledge of Ansible is required.

What You Will Learn
  • Write your own playbooks to configure servers running CentOS, Ubuntu, and Windows
  • Identify repeatable tasks and write playbooks to automate them
  • Define a highly available public cloud infrastructure in code, making it easy to distribute your infrastructure configuration
  • Deploy and configure Ansible Tower and Ansible AWX
  • Learn to use community contributed roles
  • Use Ansible in your day-to-day role and projects
In Detail

Ansible has grown from a small, open source orchestration tool to a full-blown orchestration and configuration management tool owned by Red Hat. Its powerful core modules cover a wide range of infrastructures, including on-premises systems and public clouds, operating systems, devices, and services—meaning it can be used to manage pretty much your entire end-to-end environment. Trends and surveys say that Ansible is the first choice of tool among system administrators as it is so easy to use.

This end-to-end, practical guide will take you on a learning curve from beginner to pro. You'll start by installing and configuring the Ansible to perform various automation tasks. Then, we'll dive deep into the various facets of infrastructure, such as cloud, compute and network infrastructure along with security.

By the end of this book, you'll have an end-to-end understanding of Ansible and how you can apply it to your own environments.

Style and approach

A hands-on approach to give you practical experience of writing playbooks and roles and executing them. At the end of each chapter, you'll find test questions to test your knowledge on 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 files e-mailed directly to you.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Learn Ansible
  3. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  4. Contributors
    1. About the author
    2. About the reviewer
    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. An Introduction to Ansible
    1. Ansible's story
      1. The term
      2. The software
    2. Ansible versus other tools
      1. Declarative versus imperative
      2. Configuration versus orchestration 
      3. Infrastructure as code
    3. Summary
    4. Further reading
  7. Installing and Running Ansible
    1. Technical requirements
    2. Installing Ansible
      1. Installing on macOS
        1. Homebrew
        2. The pip method
        3. Pros and cons
      2. Installing on Linux
      3. Installing on Windows 10 Professional
    3. Launching a virtual machine
    4. An introduction to playbooks
      1. Host inventories
      2. Playbooks
    5. Summary
    6. Questions
    7. Further reading
  8. The Ansible Commands
    1. Technical requirements
    2. Inbuilt commands
      1. Ansible
      2. The ansible-config command
      3. The ansible-console command
      4. The ansible-doc command
      5. The ansible-inventory command
      6. Ansible Vault
    3. Third-party commands
      1. The ansible-inventory-grapher command
      2. Ansible Run Analysis
    4. Summary
    5. Questions
    6. Further reading
  9. Deploying a LAMP Stack
    1. Technical requirements
    2. Playbook structure
    3. LAMP stack
      1. Common
        1. Updating packages
        2. Installing common packages
        3. Configuring NTP
        4. Creating a user
        5. Running the role
      2. Apache
        1. Installing Apache
        2. Configuring Apache
        3. Configuring SELinux
        4. Copying an HTML file
        5. Running the role
      3. MariaDB
        1. Installing MariaDB
        2. Configuring MariaDB
        3. Importing a sample database
        4. Running the role
      4. PHP
        1. Installing PHP
        2. The phpinfo file
        3. Adminer
        4. Running the role
      5. Overriding variables
    4. Summary
    5. Questions
    6. Further reading
  10. Deploying WordPress
    1. Technical requirements
    2. Preinstallation tasks
      1. The stack-install command
        1. Enabling the repositories
        2. Installing the packages
      2. The stack-config role
        1. WordPress system user
        2. NGINX configuration
        3. PHP and PHP-FPM configuration
        4. Starting NGINX and PHP-FPM
        5. MariaDB Configuration
        6. SELinux configuration
    3. WordPress installation tasks
      1. WordPress CLI installation
      2. Creating the WordPress database
      3. Downloading, configuring, and installing WordPress
      4. WordPress plugins and theme installation
    4. Running the WordPress playbook
    5. Summary
    6. Questions
    7. Further reading
  11. Targeting Multiple Distributions
    1. Technical requirements
    2. Launching multiple Vagrant boxes
    3. Multi-operating system considerations
    4. Adapting the roles
      1. Operating system family
      2. The stack-install role
      3. The stack-config role
      4. The wordpress role
    5. Running the playbook
    6. Summary
    7. Questions
    8. Further reading
  12. The Core Network Modules
    1. Technical requirements
    2. Manufacturer and device support
      1. The modules
        1. A10 Networks
        2. Cisco Application Centric Infrastructure (ACI)
        3. Cisco AireOS
        4. Apstra Operating System (AOS)
        5. Aruba Mobility Controller
        6. Cisco Adaptive Security Appliance (ASA)
        7. Avi Networks
        8. Big Switch Networks
        9. Citrix Netscaler
        10. Huawei CloudEngine (CE)
        11. Arista CloudVision (CV)
        12. Lenovo CNOS
        13. Cumulus Linux (CL)
        14. Dell operating system 10 (DellOS10)
        15. Ubiquiti EdgeOS
        16. Lenovo Enterprise Networking Operating System (ENOS)
        17. Arista EOS
        18. F5 BIG-IP
        19. FortiGate FortiManager
        20. FortiGate FortiOS
        21. illumos
        22. Cisco IOS and IOS XR
        23. Brocade IronWare
        24. Juniper Junos
        25. Nokia NetAct
        26. Pluribus Networks Netvisor OS
        27. Cisco Network Services Orchestrator (NSO)
        28. Nokia Nuage Networks Virtualized Services Platform (VSP)
        29. Cisco NX-OS (NXOS)
        30. Mellanox ONYX
        31. Ordnance
        32. Open vSwitch (OVS)
        33. Palo Alto Networks PAN-OS
        34. Radware
        35. Nokia Networks Service Router Operating System (SROS)
        36. VyOS
        37. System
    3. Interacting with a network device
      1. Launching the network device
      2. The VyOS role
      3. Running the playbook
    4. Summary
    5. Questions
    6. Further reading
  13. Moving to the Cloud
    1. Technical requirements
    2. Interacting with DigitalOcean
      1. Generating a personal access token
      2. Installing dopy
      3. Launching a Droplet
      4. Running the playbook
    3. WordPress on DigitalOcean
      1. The host inventory
      2. Variables
      3. The playbook
      4. The droplet role
      5. Running the playbook
    4. Summary
    5. Questions
    6. Further reading
  14. Building Out a Cloud Network
    1. Technical requirements
    2. An introduction to AWS
      1. Amazon Virtual Private Cloud overview
      2. Creating an access key and secret
    3. The VPC playbook
      1. The VPC role
      2. The subnets role
      3. The internet gateway role
      4. The security group role
      5. The ELB role
    4. Summary
    5. Questions
    6. Further reading
  15. Highly Available Cloud Deployments
    1. Technical requirements
    2. Planning the deployment
      1. Costing the deployment
      2. WordPress considerations and high availability
    3. The playbook
      1. Amazon VPC
      2. Amazon RDS
      3. Amazon EFS
      4. Testing the playbook
      5. Terminating resources
      6. EC2 instances
        1. Instance discovery
        2. New deployment
        3. Existing deployment
      7. Stack
        1. Default variables
        2. Deploy
        3. WordPress
      8. AMI
      9. Autoscaling
      10. Running the playbook
      11. Terminating all the resources
    4. Summary
    5. Questions
    6. Further reading
  16. Building Out a VMware Deployment
    1. Technical requirements
    2. An introduction to VMware
    3. The VMware modules
      1. Requirements
      2. vCloud Air
        1. The vca_fw module
        2. The vca_nat module
        3. The vca_vapp module
      3. VMware vSphere
        1. The vmware_cluster module
        2. The vmware_datacenter module
        3. The vmware_vm_facts module
        4. The vmware_vm_shell module
        5. The vmware_vm_vm_drs_rule module
        6. The vmware_vm_vss_dvs_migrate module
        7. The vsphere_copy module
        8. The vsphere_guest module
      4. VMware vCentre
        1. The vcenter_folder module
        2. The vcenter_license module
        3. The vmware_guest module
        4. The vmware_guest_facts module
        5. The vmware_guest_file_operation module
        6. The vmware_guest_find module
        7. The vmware_guest_powerstate module
        8. The vmware_guest_snapshot module
        9. The vmware_guest_tools_wait module
      5. VMware ESXi
        1. The vmware_dns_config module
        2. The vmware_host_dns_facts module
        3. The vmware_host module
        4. The vmware_host_facts module
        5. The vmware_host_acceptance module
        6. The vmware_host_config_manager module
        7. The vmware_host_datastore module
        8. The vmware_host_firewall_manager module
        9. The vmware_host_firewall_facts module
        10. The vmware_host_lockdown module
        11. The vmware_host_ntp module
        12. The vmware_host_package_facts module
        13. The vmware_host_service_manager module
        14. The vmware_host_service_facts module
        15. The vmware_datastore_facts module
        16. The vmware_host_vmnic_facts module
        17. The vmware_local_role_manager module
        18. The vmware_local_user_manager module
        19. The vmware_cfg_backup module
        20. The vmware_vmkernel module
        21. The vmware_vmkernel_facts module
        22. The vmware_target_canonical_facts module
        23. The vmware_vmotion module
        24. The vmware_vsan_cluster module
        25. The vmware_vswitch module
        26. The vmware_drs_rule_facts module
        27. The vmware_dvswitch module
        28. The vmware_dvs_host module
        29. The vmware_dvs_portgroup module
        30. The vmware_maintenancemode module
        31. The vmware_portgroup module
        32. The vmware_resource_pool module
    4. An example playbook
    5. Summary
    6. Questions
    7. Further reading
  17. Ansible Windows Modules
    1. Technical requirements
    2. Up-and-running
      1. Vagrantfile
      2. Ansible preparation
      3. The ping module
      4. The setup module
    3. Installing a web server
      1. IIS role
      2. ASP.NET role
    4. Interacting with AWS Windows instances
      1. AWS role
      2. User role
      3. Chocolatey role
      4. Information role
      5. Running the playbook
    5. Summary
    6. Questions
    7. Further reading
  18. Hardening Your Servers Using Ansible and OpenSCAP
    1. Technical requirements
    2. OpenSCAP
    3. Preparing the host
    4. The playbook
      1. Install role
      2. Scan role
      3. Running the initial scan
      4. Generating the remediation Ansible playbook
      5. Generating the remediation bash script
      6. Running a standalone scan
      7. Fixing the remaining failed checks 
      8. Destroying the Vagrant box
    5. Summary
    6. Questions
    7. Further reading
  19. Deploying WPScan and OWASP ZAP
    1. Preparing the boxes
    2. The WordPress playbook
    3. The scan playbook
      1. The Docker role
      2. Testing the playbook
      3. The WPScan role
      4. Running a WPScan
      5. The OWASP ZAP role
      6. Running OWASP ZAP
    4. Summary
    5. Questions
    6. Further reading
  20. Introducing Ansible Tower and Ansible AWX
    1. Technical requirements
    2. Web-based Ansible
    3. Ansible Tower
      1. Updating the inventory file
      2. Running the playbook
      3. Requesting a license
      4. The hello world demo project
      5. Launching the AWS playbook
        1. Adding a new project
        2. Adding credentials
        3. Adding an inventory
        4. Adding the templates
        5. Running the playbook
        6. Removing the cluster
      6. Tower summary 
    4. Ansible AWX
      1. Preparing the playbook
      2. The docker role
      3. The awx role
      4. Running the playbook
      5. Using Ansible AWX
      6. AWX summary
    5. Summary
    6. Questions
    7. Further reading
  21. Ansible Galaxy
    1. Technical requirements
    2. Introduction to Ansible Galaxy
    3. Jenkins playbook
    4. Publishing a role
      1. Creating the docker role
        1. Variables
        2. Tasks
        3. Metadata
        4. README
      2. Committing the code and publishing
      3. Testing the role
    5. Ansible Galaxy commands
      1. Logging in
      2. Importing
      3. Searching
      4. Info
    6. Summary
    7. Questions
    8. Further reading
  22. Next Steps with Ansible
    1. Integrating with third-party services
      1. Slack
        1. Generating a token
        2. The Ansible playbook
        3. Running the playbook
      2. Other services
        1. Campfire
        2. Cisco Webex Teams (Cisco Spark)
        3. CA Flowdock
        4. Hipchat
        5. Mail
        6. Mattermost
        7. Say
        8. ServiceNow
        9. Syslog
        10. Twilio
      3. Summary of third-party services
    2. The Ansible playbook debugger
      1. Debugging the task
      2. Summary of the Ansible debugger
    3. Real-world examples
      1. The chat example
      2. Automated deployment
    4. Summary
    5. Further reading
  23. Assessments
    1. Chapter 2, Installing and Running Ansible 
    2. Chapter 3, The Ansible Commands
    3. Chapter 4, Deploying a LAMP Stack
    4. Chapter 5, Deploying WordPress
    5. Chapter 6, Targeting Multiple Distributions
    6. Chapter 7, The Core Network Modules
    7. Chapter 8, Moving to the Cloud
    8. Chapter 9, Building Out a Cloud Network
    9. Chapter 10, Highly Available Cloud Deployments
    10. Chapter 11, Building Out a VMware Deployment
    11. Chapter 12, Ansible Windows Modules
    12. Chapter 13, Hardening Your Servers Using Ansible and OpenSCAP
    13. Chapter 14, Deploying WPScan and OWASP ZAP
    14. Chapter 15, Introducing Ansible Tower and Ansible AWX
  24. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think