1

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.

1 Answer 1

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.