7. Modules

7.1. About Modules

  • changes with Ansible are done by modules

  • Ansible provides a lot of common modules (called the module library)

  • common modules are written in Python

  • you can write your own modules in any language

  • Core Modules shipped with Ansible Core

  • Extra Modules via github, new also as own package

  • modules can be used to only check a state without executing

  • some modules can also be used to compare the state and show the differences

  • every module has a documentation with examples

Hint

If you’re familiar with role/profiles design pattern in Puppet, keep in mind there is no such thing in Ansible. Ansible modules are roles.

Important

Use modules, they are tested, often used and idempotent.

7.3. Run a modul as ad-hoc command

ansible -m <modul> -a <argument> <host(s)/hostgroup>

# install tree package on db hosts
ansible -m package -a "name=tree state=present" db