English
Even beginners can understand: What exactly is Ansible?
Preface: When "repetitive work" becomes a nightmare
Imagine this scenario: you just bought a new computer and need to install Chrome, WeChat, VS Code, set system preferences... After fiddling around for ages, you finally get it done.
A week later, you bought another laptop, and the same process happens all over again.
A month later, the company asks you to configure 50 servers, each needing the same software and the same configuration. Are you going to operate them manually one by one?
This is the core problem that Ansible aims to solve—letting machines automatically complete repetitive, standardized configuration tasks for you.
1. What Is Ansible? (One-Sentence Version)
Ansible is an “automation orchestration tool”. You write a "manual" (code), and it uses this manual to direct one or more machines to perform tasks, such as installing software, modifying configurations, and starting services.
Official definition: Ansible is an open-source IT automation tool that can implement Configuration Management,Application deployment,Task automation and IT orchestration.
Plain analogy:
You are like Orchestra conductor, Ansible is yours baton, the server is Musician You provide the score (Ansible scripts), and with a wave of the baton, all musicians start playing simultaneously.
You can also understand it as Smart version of copy-paste + execute, but it is much smarter than doing it manually (it checks the state and only does what needs to be done).
II. Why did Ansible emerge? (Pain point scenarios)
In the era before automation tools, operations personnel often faced:
| Scene | Problems with manual operation |
|---|---|
| Launch a new service | Logging in to 10 servers repeatedly and typing commands is error-prone. |
| Modify the configuration file | Changing each machine manually—miss one and it’s a failure. |
| System upgrade | Working overtime late at night, doing repetitive work |
| Server failure rebuild | All environments need to be reconfigured, which takes several hours. |
Ansible was born in 2012, and its author Michael DeHaan hoped to have a Simple, no client required, in human-readable language an automation tool written
III. Core Concepts of Ansible (3 Key Terms)
1. Control Node (Control Node)
It’s the computer where you installed Ansible (it can be your laptop or a jump host).
It is responsible for sending commands,No additional software needs to be installed on managed machines.
2. Managed Node (managed node)
Servers, virtual machines, network devices, etc. under your control
Only one condition needs to be met:Can connect via SSH(Windows requires WinRM)
3. Inventory (Asset List)
It's just a file that records "which machines are under my management."
The simplest way to write it:
ini
web-server-1 ansible_host=192.168.1.10
web-server-2 ansible_host=192.168.1.11
db-server ansible_host=192.168.1.204. Playbook (script)
The core of the core! A YAML-format “execution plan.”
Write clearly in it: on which machine, in what order, and what to do.
5. Task (Task)
- The smallest action unit in a Playbook, such as installing Nginx and copying configuration files.
6. Module (Module)
- Various built-in utility functions in Ansible, such as
copy(copy file),apt(installation package),service(Start/Stop Service)
IV. Ansible Workflow (One Diagram + Three Steps)
Implement the three-step approach:
Write a Playbook (for example, ensure all web servers have Nginx installed and started)
Run command:
ansible-playbook -i inventory install_nginx.ymlAnsible connects to each machine via SSH,Execute the tasks sequentially according to the steps in the Playbook.
It will first check whether Nginx is installed → if not, install it.
Check whether the service is running → if not, start it.
Key characteristics: idempotency
First run: Install Nginx
Second run: upon seeing that Nginx is already installed, do nothing.
Will not repeatedly execute the same operation, very safe
V. A practical example you’ll understand in seconds
Scenario: Install Nginx on all 3 servers
Step 1: Define the inventory file (hosts.ini)
ini
[webservers]
192.168.1.101
192.168.1.102
192.168.1.103Step 2: Write Playbook (install_nginx.yml)
yaml
---
- name: Install and start Nginx on all web servers
hosts: webservers
become: yes # Requires sudo privileges
tasks:
- name: Install Nginx
apt:
name: nginx
state: present
when: ansible_os_family == "Debian" # Only execute for Debian/Ubuntu
- name: Ensure the Nginx service is running
service:
name: nginx
state: started
enabled: yesStep 3: Execute
bash
ansible-playbook -i hosts.ini install_nginx.ymlOutput result:
PLAY [Install and start Nginx on all web servers] ***************
TASK [Gathering Facts] *********************************
ok: [192.168.1.101]
ok: [192.168.1.102]
ok: [192.168.1.103]
TASK [Install Nginx] **************************************
changed: [192.168.1.101]
changed: [192.168.1.102]
changed: [192.168.1.103]
TASK [Ensure Nginx service is running] ************************
ok: [192.168.1.101]
ok: [192.168.1.102]
ok: [192.168.1.103]
PLAY RECAP *********************************************
192.168.1.101 : ok=3 changed=1 ...Look, three machines were taken care of at the same time!
VI. What Ansible Is Not (Helping You Avoid Cognitive Misconceptions)
| misunderstanding | truth |
|---|---|
| Need to install an Agent on each machine | Relies only on SSH, no installation required |
| Can only be configured with Linux | Also supports Windows (WinRM), network devices, and cloud APIs |
| It's very complicated; you need to learn programming. | Write configuration files using only YAML—even without a programming background, you can get started. |
| Only suitable for large companies | It can also be used on a single development machine, automating the environment on your own computer. |
| is a container/orchestration tool | Not a Kubernetes replacement, but can be used in combination |
Seven, What Can Ansible Do? (Practical Scenarios)
Zero-configuration new server Get a bare-metal machine → run a Playbook → automatically install Docker and Python, configure the time zone, and create a user
One-click application deployment
git pull→ Install dependencies → Restart services → Check health statusBatch execute commands Check the memory usage of 50 servers:
ansible all -m shell -a "free -h"Configuration Backup & Drift Remediation Run the Playbook periodically to restore drifted configurations back to the correct state.
Hybrid cloud management Simultaneously operate AWS, Alibaba Cloud, and internal virtual machines
8. A Simple Comparison of Ansible and Other Tools
| tool | Characteristics | learning curve | Is an Agent needed? |
|---|---|---|---|
| Ansible | Simple, YAML, SSH | low | No |
| Puppet | Powerful, Ruby syntax | medium-high | Yes |
| Chef | Flexible, Ruby depth | High | Yes |
| SaltStack | Fast, supports remote execution | middle | Optional |
| Terraform | Specializes in infrastructure creation (IaC) | middle | No |
Ansible and Terraform are often used together: Terraform creates machines, and Ansible configures machines.
9. How to quickly get started with Ansible? (3 steps)
Step 1: Installation (Control Node)
Linux/macOS:
pip install ansibleVerification:
ansible --version
Step 2: Prepare a test machine
A local virtual machine, Docker container, or a cloud server all work.
Make sure you can connect to it via SSH.
Step 3: Write the first command (ad-hoc)
bash
# ping all machines (test connectivity)
ansible all -i "192.168.1.10," -m ping
# If successful, you already know how to use Ansible!Then you can try the Nginx Playbook above.
10. Summary: Remember Ansible in one sentence
Ansible is a powerful technology that lets you use plain-text "instructions" to direct a group of machines to do work for you. It doesn’t require installing any extra software on the machines, is intuitive, runs reliably, and can be reused repeatedly.
Who is it useful for?
Operations Engineer: Say Goodbye to Repetitive Work
Development Engineer: One-click development environment setup
Personal enthusiast: software installation after automated system reinstallation
Student: The first step in learning automation thinking
Final Thoughts
By this point, you actually understand Ansible better than most people who have just started learning IT operations. It’s not as fancy as it looks—essentially, it’s just a Can send SSH commands to multiple machines at the same time and help you remember the operation steps. tool.
In the next article, I may write a step-by-step tutorial for your first Ansible Playbook. If you are interested, leave a comment and let me know.
💡 This article is entirely based on Ansible 8.x / core 2.15+ versions, and all examples have been tested.
Appendix: Recommended Learning Resources
Official documentation: https://docs.ansible.com
Chinese community: https://www.ansible.com.cn
Free practice environment: https://play.instruqt.com/ansible