modules-and-plugins
π§© Ansible Modules & Pluginsβ
In Ansible, modules are units of workβlike installing packages, creating users, or managing files. Plugins enhance Ansibleβs core functionality like connection types, lookups, and output formatting.
π§ What are Modules?β
Modules are the building blocks used inside tasks to automate actions.
β Common Module Categoriesβ
Category | Example Modules |
---|---|
Package Mgmt | apt , yum , dnf , pip |
User & Group | user , group |
File Ops | copy , template , file |
Services | service , systemd |
Commands | command , shell , raw , script |
π§Ύ Example Task Using Modulesβ
- name: Install nginx
ansible.builtin.yum:
name: nginx
state: present
- name: Start nginx
ansible.builtin.service:
name: nginx
state: started
enabled: true
You can also find all modules here:
ansible-doc -l # List all available modules
ansible-doc copy # View help for 'copy' module
π What are Plugins?β
Plugins are extra features that modify how Ansible works. Types include:
πΉ Connection Pluginsβ
Used to control how Ansible connects:
ssh
(default)paramiko
local
πΉ Lookup Pluginsβ
Used to fetch external data:
vars:
ssh_key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
πΉ Callback Pluginsβ
Used to format output:
ANSIBLE_STDOUT_CALLBACK=debug ansible-playbook site.yml
Popular: default
, json
, yaml
, minimal
, debug
πΉ Filter Pluginsβ
Used to transform variables:
vars:
message: "{{ 'ansible' | upper }}"
π§ Best Practicesβ
- Use built-in modules where possible.
- Prefer
template
overcopy
if dynamic values are needed. - Use
ansible.builtin.<module>
for fully qualified names. - Plugins help optimize and customize execution.
β Summaryβ
Type | What it Does |
---|---|
Module | Executes a task (e.g., install package) |
Plugin | Enhances or modifies Ansible behavior |
Lookup | Fetches external info (files, vars, etc.) |
Callback | Changes playbook output format |
Connection | Controls how Ansible connects to nodes |
π Mastering modules and plugins unlocks the true power of Ansible!