# Ansible Best Practice.

**URL:** <https://forum.ansible.com/t/ansible-best-practice/19922>\
**Category:** Ansible Project\
**Created:** [December 2, 2015, 9:19pm UTC](https://forum.ansible.com/t/ansible-best-practice/19922 "2015-12-02T21:19:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_Morgan](https://avatars.discourse-cdn.com/v4/letter/j/4af34b/32.png) [@Jason\_Morgan](https://forum.ansible.com/u/Jason_Morgan)\
**Post date:** [December 2, 2015, 9:19pm UTC](https://forum.ansible.com/t/ansible-best-practice/19922/1 "2015-12-02T21:19:35Z")

</div>

I am currently developing a Playbook consisting of a number of roles via include statements as show below:

hosts: testing  
sudo: yes  
roles:

- timezone
- ntp
- mariadb
- nfs-server

I would appreciate some advice of where to put all the varables for the server eg Database , NFS exports, Timezone etc Would they be added as vars: in the main playbook ? As vars under a host\_vars directory ?

Thanks Jason

---

<div class="post-metadata">

**Author:** ![Andrew\_Edelstein](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@Andrew\_Edelstein](https://forum.ansible.com/u/Andrew_Edelstein)\
**Post date:** [December 2, 2015, 11:02pm UTC](https://forum.ansible.com/t/ansible-best-practice/19922/2 "2015-12-02T23:02:08Z")

</div>

The short answer: it depends.

The long answer: How is your network / inventory is laid out? Where the value of the variable will be unique for each server, or a single managed machine is a one-off for that variable, you’d be best to store it in host\_vars/hostname, or perhaps in the inventory file as “hostname var=value”. Where you have a group of machines in your inventory that will all share the same value, create a group\_vars/groupname file with that variable. If you need to set a unique value for everything, when a role is used in a specific play in a playbook, you can set the var as in a -vars section within the play. It can also be done on the command line with --extra-vars if it’s a one-off that should be applied to every managed machine that will be touched.

---

<div class="post-metadata">

**Author:** ![Mike\_Biancaniello](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Mike\_Biancaniello](https://forum.ansible.com/u/Mike_Biancaniello)\
**Post date:** [December 7, 2015, 4:26pm UTC](https://forum.ansible.com/t/ansible-best-practice/19922/3 "2015-12-07T16:26:56Z")

</div>

Originally, I was containing my vars within the roles, but after realizing that those vars override everything else, instead, I only populate the default/main.yml with vars inside the roles, just so things don’t error, and define everything else in my main group\_vars.

So, in my setup, when I have vars that are global, I put them in group\_vars/all/\*, then label them if there is more than one option.

e.g.  
#file: group\_vars/all/nfs\_servers

`
