An Ansible playbook is a set of instructions written in YAML that define a set of tasks to be executed on a given set of hosts. It is used to configure systems, deploy applications, and perform other IT automation tasks.

An Ansible role is a collection of related tasks, templates, files, variables, and handlers that can be used to create a playbook. It is designed to be reusable and can be shared with other users.

Example:

Ansible Playbook:


– hosts: all
become: true
tasks:
– name: Install Apache
apt: name=apache2 state=installed
– name: Start Apache
service: name=apache2 state=started

Ansible Role:


– name: apache
hosts: all
become: true
tasks:
– name: Install Apache
apt: name=apache2 state=installed
– name: Start Apache
service: name=apache2 state=started
handlers:
– name: restart apache
service: name=apache2 state=restarted

Leave a Reply

Your email address will not be published. Required fields are marked *