Master Ansible: A Beginner’s Guide to Agent‑less Automation and Configuration Management
Ansible is a simple, powerful, agent‑less automation language that uses YAML‑based playbooks to manage configurations, install software, and orchestrate tasks across Linux, Windows, Unix, and network devices; this guide explains its architecture, installation on Ubuntu, configuration files, inventory setup, and common ad‑hoc commands.
What is Ansible
Ansible is a simple, powerful, agent‑less automation language.
Benefits:
Simple and readable: written in YAML, easy for non‑developers.
Powerful: can manage configurations, install software, automate processes.
Agent‑less: no extra agents required on target machines.
Cross‑platform: supports Linux, Windows, Unix and network devices.
How Ansible Works
Ansible operates by executing a YAML‑based script called a playbook on remote systems in a defined order.
Architecture
Nodes: Control node (runs Ansible, must be Linux) and managed nodes (hosts or network devices, can be Linux or Windows).
Inventory: List of managed nodes, can be static or dynamic, grouped by attributes.
Playbook: List of tasks (plays) to run on groups of hosts; each play contains ordered tasks using modules.
Module: Executes a specific action to ensure a host reaches a desired state, e.g., yum or apt for package management.
Plugin: Extends Ansible functionality.
Installing Ansible
On Ubuntu: sudo apt install -y ansible Check version:
ansible --versionConfiguring Ansible
Default configuration file: /etc/ansible/ansible.cfg (editable only by root).
To create a custom configuration, copy the default file:
mkdir ansible
cp /etc/ansible/ansible.cfg ansible/Configuration precedence (from highest to lowest):
./ansible.cfg (current directory)
~/ansible.cfg (home directory)
/etc/ansible/ansible.cfg (system default)
Key sections in ansible.cfg include defaults (inventory path, host_key_checking, remote_user, ask_pass) and privilege_escalation (become, become_method, become_user, become_ask_pass).
[defaults]
inventory = /home/it/ansible/hosts
host_key_checking = False
remote_user = it
ask_pass = True
[privilege_escalation]
become = True
become_method = sudo
become_user = root
become_ask_pass = TrueInventory
Example static inventory file demonstrates ungrouped hosts, grouped hosts, and child groups.
# /etc/ansible/hosts
serverb
[web]
servera
[prod:children]
webUse ansible <group> --list-host to view hosts in a group.
ansible web --list-host
ansible prod --list-host
ansible all --list-host
ansible ungrouped --list-hostAd‑hoc Commands
Run a single task without a playbook, e.g., check user ID on a host: ansible servera -m shell -a "id" If using password authentication, install sshpass:
sudo apt install sshpassSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
