Operations 7 min read

Mastering Ansible: Core Architecture, Workflow, and Essential Commands

This article introduces Ansible as a model‑driven configuration manager, explains its core architecture and execution workflow, and provides detailed usage of its seven primary commands with practical code examples for automating infrastructure tasks.

Efficient Ops
Efficient Ops
Efficient Ops
Mastering Ansible: Core Architecture, Workflow, and Essential Commands

Ansible is a model‑driven configuration manager that supports multi‑node deployment and remote task execution, using SSH by default and requiring no additional software on managed nodes; it can be extended with various programming languages.

1. Ansible Basic Architecture

Core: ansible

Core Modules: modules shipped with Ansible

Custom Modules: user‑added modules when core ones are insufficient

Plugins: extend module functionality

Playbooks: task configuration files that define multiple tasks for automated execution

Connection Plugins: enable connections via SSH and other methods

Host Inventory: definition of the hosts managed by Ansible

2. Ansible Working Principle

The management node can connect to managed nodes via local, SSH, or ZeroMQ; host inventory can be categorized by application type; ad‑hoc commands execute single modules on multiple hosts, while playbooks orchestrate multiple tasks for complex operations such as web service deployment or database backup.

3. Seven Ansible Commands

1. ansible

<code>[root@localhost ~]# ansible -h
Usage: ansible [options]</code>

Executes ad‑hoc commands; default module is

command

. Example:

<code>[[email protected] ~]# ansible 192.168.0.102 -a 'date'
192.168.0.102 | success | rc=0 >>
Tue May 12 22:57:24 CST 2015</code>

2. ansible-doc

<code>ansible-doc -h
Usage: ansible-doc [options] [module...]</code>

Shows module documentation. List all modules:

<code># ansible-doc -l</code>

Show usage of a specific module (e.g.,

command

):

<code># ansible-doc -s command</code>

3. ansible-galaxy

<code>ansible-galaxy -h
Usage: ansible-galaxy [init|info|install|list|remove] [--help] [options] ...</code>

Installs roles from Ansible Galaxy . Example:

<code>[root@localhost ~]# ansible-galaxy install aeriscloud.docker
- downloading role 'docker', owned by aeriscloud
- downloading role from https://github.com/AerisCloud/ansible-docker/archive/v1.0.0.tar.gz
- extracting aeriscloud.docker to /etc/ansible/roles/aeriscloud.docker
- aeriscloud.docker was installed successfully</code>

4. ansible-lint

Checks playbook syntax:

ansible-lint playbook.yml

5. ansible-playbook

Runs a playbook file, the most frequently used command.

6. ansible-pull

Uses the pull mode (opposite of push) for scenarios with many machines or offline nodes.

7. ansible-vault

Encrypts/decrypts sensitive data in configuration files. Use with

--ask-vault-pass

when running playbooks that contain encrypted variables.

AutomationConfiguration ManagementDevOpscommand lineAnsiblePlaybooks
Efficient Ops
Written by

Efficient Ops

This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.

0 followers
Reader feedback

How this landed with the community

login 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.