# Network, vars, and role housecleaning

**URL:** <https://forum.ansible.com/t/network-vars-and-role-housecleaning/29586>\
**Category:** Ansible Project\
**Created:** [February 1, 2019, 4:32am UTC](https://forum.ansible.com/t/network-vars-and-role-housecleaning/29586 "2019-02-01T04:32:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mauricio\_Tavares](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@Mauricio\_Tavares](https://forum.ansible.com/u/Mauricio_Tavares)\
**Post date:** [February 1, 2019, 4:32am UTC](https://forum.ansible.com/t/network-vars-and-role-housecleaning/29586/1 "2019-02-01T04:32:26Z")

</div>

So I need to define lots of variables for a specific host because I am  
configuring its network (turning more interfaces on and whatnot). So I  
created a host\_vars/oddhost.yml that have lines like this:

home\_nic: "eth0"

interfaces:  
&nbsp;&nbsp;- {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vlan: 2,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nic: "{{ home\_nic }}.{{ vlan }}",  
[...]  
&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;- {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vlan: 3,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nic: "{{ home\_nic }}.{{ vlan }}",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bridge\_name: "dmzbr"  
&nbsp;&nbsp;&nbsp;&nbsp;}

First of all, is there a way to move the nic definition out of the  
dictionary so I do not need to keep on repeating it? I think not  
because it is specific to each vlan.

Second, I am hardcoding home\_nic here. But, what if I decide to have  
some script that will find which nic is the one I really need (in case  
of a multiple interface setup)? Would interfaces be only populated  
after I get home\_nic or it will try to load it before going to the  
roles? I guess I am asking about the order of events (maybe load  
global vars, host vars, somewhere get info about target host, role  
vars, and then get to the tasks in the first role it opens).

Final question is about best practices: I have a "common" roles to do  
stuff you normally do to a target host, like give it a name and create  
its users (if a package needs an user it can just access that later  
on). I also have a network role where I setup firewall rules, adjust  
sshd\_config, and do ntp client thingies. Would setting up network be  
something that belongs under common roles or network? Or am I  
overthinking?
