Master Ansible: Core Architecture, How It Works, and 7 Essential Commands
This article introduces Ansible's model‑driven configuration management, explains its core architecture and workflow, and provides detailed usage of the seven primary Ansible commands with examples and code snippets for effective automation.
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.
1. Ansible Basic Architecture
Core: ansible
Core Modules: modules shipped with Ansible
Custom Modules: user‑defined modules for additional functionality
Plugins: extend module capabilities
Playbooks: task configuration files that define multiple tasks
Connection Plugins: enable connections (SSH by default, plus others)
Host Inventory: defines the hosts managed by Ansible
2. How Ansible Works
The management side supports local, SSH, and ZeroMQ connections (SSH is default). Host inventories can be grouped by application type, enabling ad‑hoc commands for batch execution. Playbooks combine multiple tasks to implement functions such as web service deployment or database backup.
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 their usage sections.
1. ansible
ansible -hUsed for ad‑hoc commands; the default module is command. Example:
[root@localhost ~]# ansible 192.168.0.102 -a 'date'
192.168.0.102 | success | rc=0 >>
Tue May 12 22:57:24 CST 2015Parameters can be customized in ansible.cfg.
2. ansible-doc
ansible-doc -h
Usage: ansible-doc [options] [module...]Shows module information. Examples: # ansible-doc -l Lists all installed modules. # ansible-doc -s command Displays usage of a specific module.
3. ansible-galaxy
ansible-galaxy -h
Usage: ansible-galaxy [init|info|install|list|remove] [--help] [options] ...Downloads third‑party roles from Ansible Galaxy , similar to yum or pip.
[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
The most frequently used command; it reads a playbook file and executes the defined actions.
6. ansible-pull
Runs Ansible in pull mode, the opposite of the default push mode, suitable for large numbers of machines or offline nodes.
7. ansible-vault
Encrypts/decrypts sensitive variables in playbooks. Use the --ask-vault-pass option when running encrypted playbooks.
Linux Cloud Computing Practice
Welcome to Linux Cloud Computing Practice. We offer high-quality articles on Linux, cloud computing, DevOps, networking and related topics. Dive in and start your Linux cloud computing journey!
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.
