Mastering Ansible: Architecture, Workflow, and Essential Commands Explained
This article introduces Ansible as a model‑driven configuration manager, explains its core architecture and workflow, and details the seven primary commands—including ansible, ansible‑doc, ansible‑galaxy, ansible‑lint, ansible‑playbook, ansible‑pull, and ansible‑vault—providing usage examples and practical insights for effective automation.
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.
1. Ansible Basic Architecture
The diagram shows that Ansible consists of the following parts:
Core: ansible
Core Modules: built‑in modules shipped with Ansible
Custom Modules: user‑added modules when core modules are insufficient
Plugins: extend module functionality
Playbooks: task configuration files that define multiple tasks for automated execution
Connection Plugins: enable various connection methods beyond the default SSH
Host Inventory: defines the managed hosts
2. Ansible Working Principle
From the diagrams we learn that the control node can connect to managed nodes via local, SSH, or ZeroMQ, with SSH being the default. Host inventory can be classified by application type, and modules perform the required operations. Single‑module, single‑command executions are called ad‑hoc. Playbooks combine multiple tasks to implement functions such as web service deployment or database backup.
3. Seven Ansible Commands
After installing Ansible, seven primary commands are available: ansible, ansible‑doc, ansible‑galaxy, ansible‑lint, ansible‑playbook, ansible‑pull, and ansible‑vault. Below are the usage sections for each.
1. ansible
<code>[root@localhost ~]# ansible -h
Usage: ansible [options]</code>The
ansiblecommand executes ad‑hoc commands. By default it targets a host and runs the
commandmodule unless another module is specified.
<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>The default module can be changed in
ansible.cfg. Parameter explanations are shown in the following diagrams:
2. ansible‑doc
<code>ansible-doc -h
Usage: ansible-doc [options] [module...]</code>Used to view module information. Common options are
-lto list all installed modules and
-sto show details of a specific module, e.g.,
# ansible-doc -s command.
3. ansible‑galaxy
<code>ansible-galaxy -h
Usage: ansible-galaxy [init|info|install|list|remove] [--help] [options] ...</code>The command downloads third‑party roles from https://galaxy.ansible.com/, similar to yum or pip. 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
The most frequently used command; it reads a playbook file and executes the defined actions.
6. ansible‑pull
Implements the pull mode, suitable for configuring a large number of machines or machines without network connectivity.
7. ansible‑vault
Encrypts and decrypts sensitive data in configuration files. Use the
--ask-vault-passoption when running playbooks that contain vaulted variables.
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.
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.