I am trying to write my first custom module and cannot find how to locate an ansible var that is not part of the task parameters sent. For example, let’s say I want to find the ansible_ssh_host or inventory_hostname and they are not in the environment vars. I searched for import ansible.constants but could not find any examples or if this is the right module to call for this.
I am curious how for example the copy module works. There are no options to pass the user, password or server but somehow it must work. I suspect it uses ssh private keys that are set in ansible.cfg file. Is this how it works and if so how does the copy module access these values? I know I can pass whatever I want into the environment, but was hoping there was an ansible module which could access the values in ansible.cfg. I found the ansible.config.manager module and was wondering if it is used to parse the ansible.cfg file.
I was able to parse the ansible.cfg file using “ansible.module_utils.six.moves import configparser” and pull the values I am looking for. Now I just need a way to pull the remote_addr variable so I would not need to pass in the server: option from the task.