Miroslav,
Here is one work around -- design your inventory something like this:
[routers]
router1 ansible_connection=local router_user=foo router_password=bar
router2 ansible_connection=local router_user=baz router_password=biz
router3 ansible_connection=local router_user=fax router_password=fix
Here you are essentially creating an alias for each device, giving each one
an inventory hostname, but the connection is still local.
in your playbook you could do something like this (of course I've made up
these module options, as I've no idea what you've built):
- hosts: routers
gather_facts: no
tasks:
- name: configure routers
mikrotik:
user: "{{ router_user }}"
password: "{{ router_password }}"
setting: foo
This will execute against all of the hosts you've defined in the inventory
and slurp up the inventory variables you've defined, router_user,
router_password.
- James
On Wed, Mar 30, 2016 at 6:13 PM, Miroslav Hudec <[email protected]> wrote:
> Hello everyone,
>
> as a part of my Bachelor thesis I'm trying to make few modules for
> ansible, which would be used to configure MikroTik devices using API. I'm
> currently having troubles finding a way to "tell" the module things like
> hostname, username and password. I have these stored in hosts file, so I
> can use these as variables in playbook (since the connection type is
> local). Unfortunately, that makes the playbook look way too complicated,
> since every task has the exact same parts: hostname, username and password
> (and after that module-specific options). From what I've read, Ansible
> doesn't allow modules to see these variables directly because of some
> security concerns, or, whatever.
>
> That's why I decided to make a piece of code that would go trough the
> hosts file and read usernames etc. for each host. But at this point I've
> realized that I don't know how to tell that module the name of the host to
> look for. When the task will run for the host named "Router2", is there a
> way to tell that module: Hey, you're now working for Router2, try to find
> it's username etc... Or is there an entire different approach? Thank you
> for any suggestions.
>
> One last thing I'd like to know... Is there a way to use multi-file
> modules, but store the shared files in different location than
> module_utils?
>
> I want to say that I'm new to Ansible so please bear with me. I appreciate
> any suggestions. Thank you.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/08886f97-31ee-47eb-8797-ee094645e4f9%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/08886f97-31ee-47eb-8797-ee094645e4f9%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAF%3D2pTYXUJAuRFEbdvBRpxYCxp9EUHBwP%2BWhGgdpqSzO6Q-Meg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.