Accessing hostvars from within module

I’ve read that it’s possible to access hostvars directly in a module if the connection is set to local. However I’m unable to find any clues as to how this is done.

Could someone let me know if it’s in fact possible to do, and if so give me any pointers?

I know it’s an option to pass these variables as a module argument, but if possible I would prefer not to do so.

Specifically it feels redundant to have to specify a host={{ inventory_hostname }} as part of the parameters to the module.

“I’ve read that it’s possible to access hostvars directly in a module if the connection is set to local”

This is not true, there’s really no difference for local module execution, they still happen in a subprocess and they definitely should not be firing up Ansible internal APIs.

Then I can stop searching. :slight_smile: Thank you for the clarification. I’ll just use module arguments instead.

You can try using ActionModule as well.

You will not get nice api, documentation and stuff, but you will have full access to hostvars and other variables, including setting your own

Hope that helps
pr