11

I am new to Ansible. When I am using ec2.py dynamic inventory to generate inventory, after the playbook is finished to run, the results are shown as list of IP addresses under specific tag with underscore instead of dot. For example I want to run a playbook on instances with specific tag, I wonder how other people work with IP addresses?

---
- hosts: tag_test_staging
  sudo: true
  tasks:
  - name: Make sure that we can connect to the machine
    ping:

    PLAY RECAP *********************************************************************
    10_80_20_47                : ok=0    changed=0    unreachable=1    failed=0 

For private address, ec2.ini:

hostname_variable = private_ip_address
destination_variable = private_ip_address
vpc_destination_variable = private_ip_address

The results from ec2.py:

 "tag_test_staging": [
    "10_80_20_47"
  ],

For Public Address, ec2.ini:

hostname_variable = ip_address
destination_variable = public_dns_name
vpc_destination_variable = ip_address

The results from ec2.py:

 "tag_test_staging": [
    "52_28_11_11"
  ],
3
  • Why does it matter to you that the name the script gives each host has underscores for non-alphanumeric characters? Mar 4, 2017 at 19:24
  • This seems to be a very specific tool-centric question. There is ServerFault for that, and its on-topic there serverfault.com/help/on-topic. Not sure how on-topic here, if at all. Mar 5, 2017 at 9:49
  • @Evgeny, not sure I understand what do you mean, what is the point of http://devops.stackexchange.com if you do not ask questions? is it not DevOps question ?
    – Berlin
    Mar 5, 2017 at 15:50

2 Answers 2

5

It works if I comment out the hostname_variable, because it allow to override the inventory_name with an ec2 variable, instead of using the destination_variable

#hostname_variable = private_ip_address
#hostname_variable = ip_address
destination_variable = public_dns_name
vpc_destination_variable = private_ip_address

For Private IPs:

destination_variable = private_ip_address
3
  • Alas, I am seeing the same behavior, and commenting out hostname_variable doesn't correct it. Jun 14, 2018 at 20:26
  • However.... I have several times now noticed that changing the ini file and re-running ec2.py won't immediately return the correct information. Weird AF, right? But after several times trying it and trying it and trying it, after about 20 minutes it suddenly started returning IP addresses with dots instead of underscores! I dunno. Jun 14, 2018 at 20:33
  • Do you know what can I do if I want to make a condition? e.g. vpc_destination_variable: "{{ ip_address if ec2_platform == 'windows' else private_ip_address }}" Dec 26, 2019 at 8:42
0

I had the same issue. I was getting back ip addresses with underscores instead of dots. But I have several times now noticed that changing the ini file and re-running ec2.py won't immediately return the correct information. Once I changed to private_ip_address and it kept returning private_dns_name for a while. This time, after changing to private_ip_address and re-running it several times -- trying it and trying it and trying it -- after about 20 minutes it suddenly started returning IP addresses with dots instead of underscores! I dunno. Weird AF, right?

2
  • Sounds like a caching “issue”. Have you tried to alter the ‘cache_max_age’ parameter in ec2.ini?
    – malte
    Aug 25, 2018 at 22:21
  • You're probably completely right. I was just looking at that today, actually. You can run "./ec2.py --refresh-cache". Aug 27, 2018 at 22:34

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.