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.
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
[root@localhost ~]# ansible -h
Usage: ansible [options]Executes ad‑hoc commands; default module is command. Example:
[[email protected] ~]# ansible 192.168.0.102 -a 'date'
192.168.0.102 | success | rc=0 >>
Tue May 12 22:57:24 CST 20152. ansible-doc
ansible-doc -h
Usage: ansible-doc [options] [module...]Shows module documentation. List all modules: # ansible-doc -l Show usage of a specific module (e.g., command): # ansible-doc -s command 3. ansible-galaxy
ansible-galaxy -h
Usage: ansible-galaxy [init|info|install|list|remove] [--help] [options] ...Installs roles from Ansible Galaxy . 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 successfully4. 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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
