Operations 7 min read

Mastering Ansible: Core Architecture, Workflow, and Essential Commands

This article introduces Ansible as a model‑driven configuration manager, explains its basic architecture and working principles, and provides detailed usage of its seven core commands with practical code examples for automation and DevOps 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. It uses SSH by default, requires no additional software on managed nodes, and can be extended with various programming languages.

Ansible Basic Architecture

The architecture consists of the following components:

Core: ansible

Core Modules: built‑in modules provided by Ansible

Custom Modules: user‑defined modules to extend functionality

Plugins: supplemental extensions for modules

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

Connection Plugins: enable connections via SSH, local, ZeroMQ, etc.

Host Inventory: definition of the managed hosts

Ansible Working Principle

The management side can connect to managed nodes via local, SSH, or ZeroMQ, with SSH being the default. Hosts can be grouped in the inventory by application type or other criteria. Single‑module, single‑command executions are called ad‑hoc commands, while Playbooks combine multiple tasks to perform complex operations such as web service deployment or database backup.

Seven Essential Ansible Commands

1. ansible

<code># ansible -h
Usage: ansible [options]
</code>

Used for ad‑hoc commands. Example:

<code># 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>

List all installed 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 install aeriscloud.docker
- downloading role 'docker', owned by aeriscloud
- extracting aeriscloud.docker to /etc/ansible/roles/aeriscloud.docker
- aeriscloud.docker was installed successfully
</code>

Installs roles from the Ansible Galaxy repository, similar to yum or pip.

4. ansible-lint

Checks Playbook syntax:

<code># ansible-lint playbook.yml
</code>

5. ansible-playbook

Executes a Playbook file to perform defined tasks.

6. ansible-pull

Runs Ansible in pull mode, suitable for configuring a large number of machines or operating on hosts without network connectivity.

7. ansible-vault

Encrypts and decrypts sensitive data in configuration files. Use with the

--ask-vault-pass

option to run 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.