Question: How do I get hostname as well as ansible_host in ansible module ??

Hi All,

I develop and maintain the Ansible role: Juniper.junos(https://github.com/Juniper/ansible-junos-stdlib). For the context of the issue, please refer to https://github.com/Juniper/ansible-junos-stdlib/issues/468.

Consider the following scenario wherein the user has provided both hostname and IP. Currently, the module parameters only include host. Is there any way that I can get the hostname of the target device as well ??

/etc/ansible/hosts.yml

[vMX]
my-qfx-a ansible_host=xx.xx.xx.xx

The module receives the following parameters during invocation, which don’t contain the hostname

{
'comment': None,
'load': None,
'remove_ns': None,
'retrieve': 'committed',
'vars': None,
'attempts': None,
'host': 'xx.xx.xx.xx',
'diff': None,
'port': 22,
'ignore_warning': None,
'confirmed': None,
'console': None,
'namespace': None,
'check': None,
'dest': None,
'logdir': None,
'template': None,
'provider': None,
'dest_dir': 'saved',
'commit_empty_changes': False,
'baud': None,
'rollback': None,
'format': 'set',
'passwd': 'xxxxx',
'cs_user': None,
'ssh_config': None,
'return_output': False,
'user': 'xxxx',
'logfile': 'abcd.log',
'diffs_file': None,
'src': None,
'level': None,
'url': None,
'lines': None,
'check_commit_wait': None,
'cs_passwd': None,
'filter': None,
'mode': None,
'timeout': 30,
'commit': None,
'model': None,
'ssh_private_key_file': None,
'options': {
'database': 'committed',
'format': 'set'
  },
'config_mode': 'exclusive'
}

Regards,
Raja Shekar