Ansible

ansible.com

🌐 Resources πŸ”—

Blogs:


  • Open-source tool for automation and configuration management

  • Agentless: Uses SSH or WinRM for communication

  • YAML-based playbooks for defining configurations

  • Idempotent: Applies changes without unintended side effects

  • Modular: Offers built-in modules for various tasks

  • Roles: Organizes tasks for better reuse and collaboration

  • Strong community support and extensive documentation

Terminology

  • Control Node: The system running Ansible, typically on Linux/Unix

  • Managed Nodes: Target systems controlled by Ansible, requiring SSH and Python (2.6+/3.5+). Supports various OS types, including Windows

  • Inventory: A file listing managed hosts. Can be static (.ini) or dynamic (JSON output) for project-specific management

  • Tasks: Units of work executed on managed nodes, either ad-hoc or within playbooks

  • Playbook: An ordered list of tasks specifying target hosts and execution details, written in YAML

  • Handlers: Special tasks for managing services, triggered by other tasks and run after all tasks are completed

  • Roles: Structured collections of playbooks and files for reusable automation packages, streamlining specific deployments


  • Generate ansible.cfg file

  • Even if you do not define any groups in your inventory file, Ansible creates two default groups: all and ungrouped. The all group contains every host. The ungrouped group contains all hosts that don’t have another group aside from all.


Commands


Labs

Playbooks


Semaphore UI

Semaphorearrow-up-right is a powerful open-source tool for managing Ansible tasks through a web-based interface. This guide demonstrates how to install Semaphore on an Ubuntu Desktop VM using Snap (❗) and configure it for SSH-based Ansible playbooks.

❗ As per Semaphore docsarrow-up-right Snap install is deprecated (but still works).

Install via Snap (Ubuntu Desktop)

Install via Docker

Not tested

Follow the steps outlined in the official Semaphore documentationarrow-up-right for Docker-based deployment. Use the container configuratorarrow-up-right to get the ideal Docker configuration for Semaphore.

Here is a summary for convenience to deploy via docker with data persistence:

Post-install configuration

  1. Log In

  2. Keystore Configuration

    • Add the SSH keys + passphrases for secure connections

  3. Repository Configuration

    • Link the Git repository using SSH credentials

    • e.g. - [email protected]:syselement/ansibletest.git

  4. Environment

    • Set up an empty environment

  5. Static Inventory Configuration

    • Define an inventory file with host and group details

    • e.g.

Creating Ansible Task Templates

Task templates in Semaphore point to Ansible playbooks stored in the repository. Here’s how to set them up:

  1. Organize the repository

    • Structure the repository to store playbooks logically.

    • e.g.

  1. Create a template in Semaphore

    • Add a new Task Template in Semaphore

      • e.g.

      • Name - AptUpdateUbuntu

        • Playbook Path - Relative path to the playbook - ansible/playbooks/updatelinux.yaml


Last updated