Ansible Roles and Variables
While automation is great, we have to be careful not to recreate past problems. What I mean is that playbooks should be written in a generic fashion that can be applied to more than one host. If we’re writing playbooks that only work on one single host, we aren’t much further ahead than we were before.
Two of the key components of making playbooks reusable are Ansible variables and roles. Let’s try and define each of them individually and while showing some examples along the way.
Roles
Roles allow you to call a set of variables, tasks, and handlers by simply specifying a defined role. Roles require the use of a defined file structure in order to work. Per the Ansible documentation, that structure looks like this…
Roles are really just a way to split up your playbook into smaller reusable parts. For instance, let’s consider we added another host to our lab…
---
- hosts: linuxservers
tasks:
- name: Install Apache Web Server
yum: name=httpd state=latest
notify:
- openport
- startwebserver
handlers:
- name: openport
service: name=httpd state=started
- name: startwebserver
firewalld: port=80/tcp permanent=true state=enabled immediate=yes
- hosts: Continue reading
It's not about containers or Docker. CoreOS claims a bigger mission.
Special thanks to all who joined us and submitted questions to the Pluribus Network Virtualization Report Webinar. The full event recording and Q&A are now available!
Take survey and enter to win one of two $200 Amazon Gift Cards.
