Accessing host variables directly in python module

12 views
Skip to first unread message

Miroslav Hudec

unread,
Jan 4, 2016, 10:24:38 AM1/4/16
to Ansible Project
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
Reply all
Reply to author
Forward
0 new messages