Allen Han
Allen Han

Reputation: 3

Ansible-Inventory AWS_EC2 plugin how to show hostnames and private ips

Is there anyway to template hostnames with the aws ec2 plugin? This is my inventory script:

plugin: aws_ec2
keyed_groups:
  - key: tags.role
    prefix: aws
hostnames:
  - tag:Name
  - private-ip-address
groups:
    integration: group_names

Running ansible-inventory -i integration.aws_ec2.yml --graph gives me this

@all:
  |--@aws_apilb:
  |  |--apilb001.core.int.ec2.corp.pvt
  |--@aws_bastion:
  |  |--core-bastion
  |  |--ops-bastion
  |  |--webint-bastion-bastion

But I want something like this where the private ip is included. I can get one or the other by either removing tag:Name or keeping it but I want both.

@all:
  |--@aws_apilb:
  |  |--apilb001.core.int.ec2.corp.pvt (10.111.0.111)
  |--@aws_bastion:
  |  |--core-bastion  (10.111.0.112)
  |  |--ops-bastion  (10.111.0.113)
  |  |--webint-bastion-bastion  (10.111.0.113)

Upvotes: 0

Views: 1016

Answers (2)

Life5ign
Life5ign

Reputation: 202

Use this content for hostnames:

hostnames:
  - name: 'private-ip-address'
    separator: '_'
    prefix: 'tag:Name'

sample output: myNameTag_myPrivate_ip

Upvotes: 0

Moon
Moon

Reputation: 3047

I doubt if there is a way at this moment (ansible v2.9) to do what you are looking for. However, I could find a pending issue requesting for the similar feature which could be available on ansible v2.10.

In the meantime, you can override the existing plugin as suggested here.

Upvotes: 1

Related Questions