Operations 8 min read

Master Ansible: Architecture, Workflow, and 7 Key Commands

Ansible is a model-driven configuration manager that uses SSH for remote connections, featuring a core engine, modules, plugins, playbooks, connection plugins, and host inventories; this guide explains its architecture, operation flow, and details the seven primary commands with usage examples.

Open Source Linux
Open Source Linux
Open Source Linux
Master Ansible: Architecture, Workflow, and 7 Key Commands
Source: 云原生之路 Link: https://www.361way.com/ansible-framework/4393.html

Ansible is a model‑driven configuration manager that supports multi‑node deployment and remote task execution. It uses SSH by default for remote connections, requires no additional software on managed nodes, and can be extended with various programming languages.

1. Ansible Basic Architecture

The diagram shows the basic architecture of Ansible, which consists of the following components:

Core: ansible

Core Modules: built‑in modules provided by Ansible

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

Plugins: supplemental functionality for modules

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

Connection Plugins: enable connections to hosts via SSH or other methods

Host Inventory: definition of the hosts managed by Ansible

2. Ansible Working Principle

From the diagrams we can see:

1. The control node supports local, SSH, and ZeroMQ connection methods, with SSH being the default, corresponding to the connection plugins in the basic architecture.

2. Host inventories can be classified by application type or other criteria; the control node performs operations via modules, enabling ad‑hoc batch execution of single commands.

3. Playbooks allow grouping multiple tasks to achieve a specific function, such as installing a web service or backing up databases, effectively combining several ad‑hoc operations.

3. Seven Ansible Commands

After installing Ansible, you have seven primary commands: ansible, ansible-doc, ansible-galaxy, ansible-lint, ansible-playbook, ansible-pull, and ansible-vault. Below are the usage snippets for each.

1. ansible

[root@localhost ~]# ansible -h
Usage: ansible [options]

The ansible command executes ad‑hoc commands. Example:

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

By default it uses the command module, which can be changed in ansible.cfg. The following images illustrate its options:

2. ansible-doc

ansible-doc -h
Usage: ansible-doc [options] [module...]

Used to view module information. Examples: # ansible-doc -l Lists all installed modules. # ansible-doc -s command Shows usage for the command module.

3. ansible-galaxy

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

Facilitates downloading third‑party roles from https://galaxy.ansible.com/, similar to yum or pip. Example:

[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

4. ansible-lint

Checks playbook syntax: ansible-lint playbook.yml.

5. ansible-playbook

The most frequently used command; it reads a playbook file and executes the defined actions.

6. ansible-pull

Operates in pull mode, opposite to the usual push mode, suitable for configuring a large number of machines or for machines without network connectivity.

7. ansible-vault

Encrypts/decrypts sensitive data in configuration files. When running a playbook that contains encrypted variables, add the --ask-vault-pass option to prompt for the password.

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 ManagementDevOpscommand-lineInfrastructureAnsiblePlaybooks
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

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.