Ansible Automation Overview

Jul 13, 2024

Ansible: Open Source Automation Tool

Overview

  • Created by Michael DeHaan in 2012
  • Acquired by Red Hat
  • Popular configuration management tool

Key Features

  • Uses declarative, push-based YAML code
  • Automates Linux servers
  • Increases efficiency and reduces human error

How It Works

  • Control Node: At least one machine serves as the control node
  • Managed Nodes: Connects to multiple managed nodes over SSH
  • Modules: Sends Ansible modules over SSH to configure dependencies, update network settings, provision databases, etc.

Playbooks

  • Definition: Contains a series of jobs called plays
  • Plays: Set of instructions executed on one or more target hosts
  • Execution: Executes tasks in order against all machines in parallel
  • Idempotence: No changes are made unless necessary

Real-World Use Case

  • Manage Linux servers on platforms like Linode
  • Steps:
    1. Provision a server running Ubuntu as the control node
    2. SSH into control node and install Ansible
    3. Obtain and securely store access token for Linode API
    4. Use Ansible Galaxy to access pre-built playbooks
    5. Use Ansible Vault to store sensitive info securely
    6. Write a playbook
      • Name the play (e.g., "Create Linode Instance")
      • Define hosts (pattern or inventory file)
      • Define reusable variables
      • Create task list with instructions
      • Example: linode.cloud.instance namespace for creating a new server instance
    7. Run the playbook to automate infrastructure

Steps to Write First Playbook

  1. Create a YAML file in the development directory
  2. Name the play and define the host property
  3. Define reusable variables or reference variable files
  4. Create a task list with detailed instructions (e.g., configuring API token, region, disk image)
  5. Execute using ansible-playbook command

Key Commands and Practices

  • Install Collections: ansible-galaxy command to install collections
  • Secure Storage: Use ansible-vault for sensitive data
  • Run Playbook: ansible-playbook command

Shoutout

  • Sponsored by Linode Cloud Computing (Akamai)

Thank you for watching!