ansible devops moc

Core Idea

Ansible is agentless, Python-driven IT automation: describe hosts in an inventory, act through modules and playbooks, and organize everything in a standard directory layout with roles.

  • What it is: command-line IT automation for configuration management, application deployment, and orchestration.
  • Concepts defined: host, group, inventory, modules, tasks, playbooks, roles.
  • The directory layout best practice: inventory, group_vars, host_vars, roles, playbooks.

Main Resources Used

  1. Ansible Up & Running
    A comprehensive guide to getting started with Ansible, covering the basics and advanced topics for effective automation.
  2. Ansible for DevOps
    A practical guide with examples for using Ansible in real-world DevOps scenarios.
  3. Ansible Documentation
    The official Ansible documentation for in-depth reference and the latest updates.
  4. KodeKloud Ansible Advance Course

What is Ansible ?

Ansible is an open source, command-line IT automation software application written in Python. It can configure systems, deploy software, and orchestrate advanced workflows to support application deployment, system updates, and more.

Ansible is a tool for IT automation that handles tasks like configuration management, application deployment, and orchestration

Basic Concepts & Terms

Host:Β A remote machine managed by Ansible.

Group:Β Several hosts grouped together that share a common attribute.

Inventory:Β A collection of all the hosts and groups that Ansible manages. Could be a static file in the simple cases or we can pull the inventory from remote sources, such as cloud providers.

Modules:Β Units of code that Ansible sends to the remote nodes for execution.

Tasks:Β Units of action that combine a module and its arguments along with some other parameters.

​​Playbooks:Β An ordered list of tasks along with its necessary parameters that define a recipe to configure a system.
03. Playbooks

Roles:Β Redistributable units of organization that allow users to share automation code easier.

Ansible Tutorial for Beginners: Playbook & Examples

Directory Layout

Best Practices β€” Ansible Documentation

ansible-project/
β”œβ”€β”€ ansible.cfg          # Configuration file for Ansible
β”œβ”€β”€ inventory/           # Inventory files or directories
β”‚   β”œβ”€β”€ production       # Production inventory
β”‚   └── staging          # Staging inventory
β”œβ”€β”€ group_vars/          # Variables for groups
β”‚   β”œβ”€β”€ all.yml          # Variables for all groups
β”‚   β”œβ”€β”€ webservers.yml   # Variables for webservers group
β”‚   └── dbservers.yml    # Variables for database servers group
β”œβ”€β”€ host_vars/           # Variables for specific hosts
β”‚   β”œβ”€β”€ host1.yml
β”‚   └── host2.yml
β”œβ”€β”€ roles/               # Role definitions
β”‚   β”œβ”€β”€ common/          # Common role
β”‚   β”‚   β”œβ”€β”€ tasks/       # Tasks for the common role
β”‚   β”‚   β”‚   └── main.yml
β”‚   β”‚   β”œβ”€β”€ handlers/    # Handlers for the common role
β”‚   β”‚   β”‚   └── main.yml
β”‚   β”‚   β”œβ”€β”€ templates/   # Templates for the common role
β”‚   β”‚   β”œβ”€β”€ files/       # Files for the common role
β”‚   β”‚   β”œβ”€β”€ vars/        # Variables for the common role
β”‚   β”‚   β”‚   └── main.yml
β”‚   β”‚   β”œβ”€β”€ defaults/    # Default variables for the common role
β”‚   β”‚   β”‚   └── main.yml
β”‚   β”‚   β”œβ”€β”€ meta/        # Metadata for the common role
β”‚   β”‚   β”‚   └── main.yml
β”‚   β”‚   └── README.md    # Documentation for the role
β”‚   └── webservers/      # Webservers role (same structure as common)
β”œβ”€β”€ playbooks/           # Playbooks
β”‚   β”œβ”€β”€ site.yml         # Main playbook
β”‚   β”œβ”€β”€ webservers.yml   # Playbook for webservers
β”‚   └── dbservers.yml    # Playbook for database servers
β”œβ”€β”€ library/             # Custom modules
β”œβ”€β”€ filter_plugins/      # Custom filter plugins
└── README.md            # Documentation for the project