Roles vs Playbooks vs Groups

34 views
Skip to first unread message

Hans Fritz

unread,
Jul 18, 2017, 8:39:27 AM7/18/17
to Ansible Project
I'm confused about roles vs playbooks vs groups in the inventory.

I have written a role that I called base. It's a role I that configures any box I want to use, it sets basic things like the SSH server, automatic updates, etc.

In my inventory, I have a host (boole) that I want to have the base role, and some NFS shares (using an off the shelf NFS role). I also have another host (einstein) that I want to have the base role, and say, a web server (using an off the shelf nginx role).

How do I go about playbooks in this case? Do I name my playbook `boole`, and the other `einstein`? Or do I name them `nfs-server`, and `web-server`? Do I use `hosts: all` in my playbooks and specify the hosts/groups when invoking the playbook, or do I use the group/hosts' names in the playbook and use `all` when invoking the command line playbook run?

Brian Coca

unread,
Jul 18, 2017, 9:20:01 AM7/18/17
to Ansible Project
So this is the 'short' story:

Playbook = contains Plays

Inventory = definition of your targets (where)

Task = ensures an action (what)

Play = maps hosts to tasks (decides what runs where)

Role = grouping of tasks, vars and other resources for reuse
(optional, roles are a convenience)


As to how to setup plays/hosts: entries, that depends on your
environment and workflow.
Ansible allows for many variations so it is valid to have hosts: all
and then use --limit to target specific hosts or be specific in the
play hosts: web-server.

My choice would be to create a play for each group and apply the tasks
and roles you want for that group, then you can create a playbook that
includes all these.
This gives you flexibility of 'full system execution' or 'specific
subsystem' by selecting which playbook, there are other ways to do
this (i.e tags) but IMHO this is the simplest.



----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages