# Accessing host variables directly in python module

**URL:** <https://forum.ansible.com/t/accessing-host-variables-directly-in-python-module/20110>\
**Category:** Ansible Project\
**Created:** [January 3, 2016, 6:24pm UTC](https://forum.ansible.com/t/accessing-host-variables-directly-in-python-module/20110 "2016-01-03T18:24:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miroslav\_Hudec](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@Miroslav\_Hudec](https://forum.ansible.com/u/Miroslav_Hudec)\
**Post date:** [January 3, 2016, 6:24pm UTC](https://forum.ansible.com/t/accessing-host-variables-directly-in-python-module/20110/1 "2016-01-03T18:24:41Z")

</div>

Hi everyone,

first of all, I am sorry if this is documented somewhere else.

I am trying to write few modules which would be used for configuring MikroTik devices over API. My “problem” is, that in playbooks I always have to use at least 3 always-the-same arguments for each module. For example:

`

- name: Mikrotik TEST  
hosts: mikrotik  
connection: local  
gather\_facts: no  
vars:  
dhcp\_pool: testpool  
tasks:
- name: DNS Setup  
mt\_dns: username={{username}} hostname={{hostname}} password={{password}} servers=192.168.1.1
- name: IP address setup  
mt\_ip: username={{username}} hostname={{hostname}} password={{password}} address=192.168.2.1/24 interface=ether10-slave-local disabled=“false”
- name: DHCP Pool Setup  
mt\_ip\_pool: username={{username}} hostname={{hostname}} password={{password}} pool\_name={{dhcp\_pool}} pool\_range=192.168.2.10-192.168.2.20
- name: DHCP Server Setup  
mt\_dhcp\_srv: username={{username}} hostname={{hostname}} password={{password}} name=TestServer address\_pool={{dhcp\_pool}} disabled=“false” interface=ether10-slave-local
- name: DHCP Options Setup  
mt\_dhcp\_network: username={{username}} hostname={{hostname}} password={{password}}

`

In my opinion, this makes the playbook a bit confusing… Is there any way how to make ansible push host variables right into module, without the need to call them from playbook? Using either hosts file or host\_vars directory? Or is this a no-go for ansible and could only by done outside ansible? I am new to ansible and will appreciate any advice. Thanks
