Skip to main content

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​

CategoryExample Modules
Package Mgmtapt, yum, dnf, pip
User & Groupuser, group
File Opscopy, template, file
Servicesservice, systemd
Commandscommand, 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 over copy if dynamic values are needed.
  • Use ansible.builtin.<module> for fully qualified names.
  • Plugins help optimize and customize execution.

βœ… Summary​

TypeWhat it Does
ModuleExecutes a task (e.g., install package)
PluginEnhances or modifies Ansible behavior
LookupFetches external info (files, vars, etc.)
CallbackChanges playbook output format
ConnectionControls how Ansible connects to nodes

πŸš€ Mastering modules and plugins unlocks the true power of Ansible!