Ansible dynamic inventory using AWS plugin -- how to obtain internal DNS records or private IP? Seeking help from those who've worked with dynamic inventory in Ansible.
I have Ansible set up with the aws_ec2 plugin (not using the python script as it's been too problematic). Currently, I'm only using an aws_ec2.yaml file as my inventory and variable source of truth.
When I run ansible-inventory --graph, Ansible returns my instances as public AWS DNS hostnames. I want either private DNS hostname or IP address so I SSH will against the hosts (we have firewall rule blocking ssh against the public AWS hostname).
How can I instruct the aws_ec2 module to do this via the plugin? Thanks.
The hostnames parameter controls what the plugin uses as the host name. It accepts a list of attributes, and will use the first one that the instance has defined:
hostnames:
  - private-dns-name
  - private-ip-address

You can also set the ansible_host variable using compose. This changes the connection target without modifying the inventory hostname:
compose:
  # Note the underscores; this functionality uses the Ansible variable names instead of the raw AWS attributes.
  ansible_host: private_ip_address