Operations 7 min read

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.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Mastering Ansible: A Beginner’s Guide to Operations Automation

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.

Ansible architecture diagram
Ansible architecture diagram

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" webhosts

Defining 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=guoting

Common 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):

Time info example
Time info example

2) Add a user on the control node (using user module):

Add user example
Add user example

3) Implement SSH key authentication (using shell and copy modules):

SSH key authentication example
SSH key authentication example

After configuring SSH keys, the /etc/ansible/hosts file can be simplified to:

[webhosts]
172.16.10.22
172.16.10.33

4) Install software and start services (using yum and service modules):

Install and start service example
Install and start service example
Service management example
Service management example

5) Use the raw module for pipeline commands (similar to shell):

Raw module example
Raw module example

Conclusion

This overview covers the basic concepts and usage of Ansible; the next article will explore advanced batch deployment techniques.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Configuration ManagementDevOpsInfrastructure as CodeOperations AutomationAnsible
MaGe Linux Operations
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.