Define automation that can be reused in multiple plays and even shared for others to use on Ansible Galaxy.
A role can define variables with defaults that can be overrided by the consumers to customize its behaviors.
You can facilitate the reuse of the role playbooks by creating a self-referencing symbolic link via running the following commands after replacing the placeholder strings in the project directory in a text terminal:
ln_opts=(
# Create symbolic link instead of hard link
--symbolic
# Use relative path as link destination to prevent broken links if the hosting project's path changes
--relative
# Overwrite existing links
--force
# Increase verbosity
--verbose
)
ln "${ln_opts[@]}" . playbooks/roles/_namespace_._name_
The following materials are referenced during the writing of this README:
- Roles — Ansible Community Documentation
Explains the basic information of Roles in Ansible. - Re-using Ansible artifacts — Ansible Community Documentation
Explains how to reuse Ansible artifacts in general. - Roles — Glossary — Ansible Community Documentation
Explains the usage of the "role" Ansible term.