Ansible Contd
Ansible Roles and Collections
- DRY (Dont Repeat Yourself) Principle: This speaks about reusability
- Ansible has 3 popular ways of reusability
- including or importing ansible playbooks
- using roles
- using collections
- Reusability can be acheived in two ways
- reusable tasks in the form of roles or collections or playbooks
- this requires re-arranging the playbooks
- reusable modules:
- This requires writing python code
- reusable tasks in the form of roles or collections or playbooks
-
Re-using tasks:
- import or include tasks
- Example with include tasks Refer Here
Roles
- Role is a reusable playbook. Refer Here
- Ansible Galaxy hosts lots of reusable community roles Refer Here
- Refer Here for the changes done to install apache using community role
- Refer Here for refactoring playbook into role
Ansible Variables
- special variables Refer Here
- magic variables Refer Here
- both magic and special varibales provide information about ansible Refer Here
