Mastering Ansible: A Beginner’s Guide to Operations Automation
This article introduces Ansible as a powerful, agentless automation tool for operations engineers, covering the tasks suitable for batch deployment, its architecture, core concepts like idempotence, essential components, basic command usage, and practical examples such as installing software, managing users, and configuring SSH keys.
Why Operations Automation?
Operations automation is the inevitable direction of operations development and the essential choice for engineers seeking maximum efficiency.
This article focuses on one of the most popular tools, Ansible , to illustrate key concepts.
1. Tasks Suitable for Batch Deployment
Operating system installation (e.g., Cobbler, Red Hat Satellite)
Operating system configuration (e.g., CFEngine, Puppet, Chef, Func)
Batch program deployment
Batch command execution and status monitoring
2. Introduction to Ansible
Ansible is a Python‑based automation tool that combines the strengths of many traditional operations tools, providing agentless, idempotent batch operations.
Typical operations tools work in two modes:
Agent mode: based on SSL, works on the monitored host (e.g., Puppet). Agentless mode: based on SSH, the control node communicates with the monitored host via SSH.Ansible operates in agentless mode and guarantees idempotence —the same instruction will not be executed repeatedly, such as reinstalling a package.
Key components:
Connection plugins – handle communication with target hosts.
Host Inventory – a configuration file that lists the managed hosts.
Modules – core modules like command, custom modules, etc.
Logging/email plugins – provide logging and notification.
Playbooks – scripts that can run multiple tasks on hosts in a single run.
3. Basic Ansible Usage
Installing software with yum:
ansible -m yum -a "name=vim state=present" webhostsDefining the inventory file ( /etc/ansible/hosts):
# vim /etc/ansible/hosts
[webhosts]
172.16.10.22 ansible_ssh_user=root ansible_ssh_pass=guoting
172.16.10.33 ansible_ssh_user=root ansible_ssh_pass=guotingCommon commands:
Show module documentation: ansible-doc copy List available modules: ansible-doc -l Run a module on a host pattern:
ansible <host-pattern> -m <module> -a '<module arguments>'4. Ansible Examples
1) View time information (using command or shell modules):
2) Add a user on the control node (using user module):
3) Implement SSH key authentication (using shell and copy modules):
After configuring SSH keys, the /etc/ansible/hosts file can be simplified to:
[webhosts]
172.16.10.22
172.16.10.334) Install software and start services (using yum and service modules):
5) Use the raw module for pipeline commands (similar to shell):
Conclusion
This overview covers the basic concepts and usage of Ansible; the next article will explore advanced batch deployment techniques.
Signed-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.
