<p>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?</p>

CC BY-SA 4.0
2018-08-25T22:21:17.973Z
Sounds like a caching “issue”. Have you tried to alter the ‘cache_max_age’ parameter in ec2.ini?
malte
CC BY-SA 4.0
2018-08-27T22:34:56.160Z
You're probably completely right. I was just looking at that today, actually. You can run "./ec2.py --refresh-cache".
Todd Walton
CC BY-SA 4.0
2018-06-14T20:36:09.100Z
2018-06-14T20:36:09.100Z
Todd Walton
<p>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</p>

<pre><code>#hostname_variable = private_ip_address
#hostname_variable = ip_address
destination_variable = public_dns_name
vpc_destination_variable = private_ip_address
</code></pre>

<p>For Private IPs:</p>

<pre><code>destination_variable = private_ip_address
</code></pre>

CC BY-SA 4.0
2018-06-14T20:26:48.747Z
Alas, I am seeing the same behavior, and commenting out hostname_variable doesn't correct it.
Todd Walton
CC BY-SA 4.0
2018-06-14T20:33:41.273Z
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.
Todd Walton
CC BY-SA 4.0
2019-12-26T08:42:50.910Z
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 }}"
adam
CC BY-SA 3.0
2017-03-04T15:24:04.863Z
2017-03-04T15:24:04.863Z
Berlin
<p>I am new to Ansible. When I am using <code>ec2.py</code> 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? </p>

<pre><code>---
- 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 
</code></pre>

<p>For private address, ec2.ini:</p>

<pre><code>hostname_variable = private_ip_address
destination_variable = private_ip_address
vpc_destination_variable = private_ip_address
</code></pre>

<p>The results from ec2.py:</p>

<pre><code> "tag_test_staging": [
    "10_80_20_47"
  ],
</code></pre>

<p>For Public Address, ec2.ini:</p>

<pre><code>hostname_variable = ip_address
destination_variable = public_dns_name
vpc_destination_variable = ip_address
</code></pre>

<p>The results from ec2.py:</p>

<pre><code> "tag_test_staging": [
    "52_28_11_11"
  ],
</code></pre>

CC BY-SA 3.0
2017-03-04T19:24:40.133Z
Why does it matter to you that the name the script gives each host has underscores for non-alphanumeric characters?
Assaf Lavie
CC BY-SA 3.0
2017-03-05T09:49:32.880Z
This seems to be a very specific tool-centric question. There is ServerFault for that, and its on-topic there http://serverfault.com/help/on-topic. Not sure how on-topic here, if at all.
Evgeny Zislis
CC BY-SA 3.0
2017-03-05T15:50:02.410Z
@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
<ansible>
Ansible Dynamic Inventory - generate inventory with ip addresses under specific tag with underscore instead of dot
Berlin
# Ansible Dynamic Inventory - generate inventory with ip addresses under specific tag with underscore instead of dot

(Asked by: username_0 on 2017-03-04)

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"
  ],

**Tags:** ansible

> **Comments:**
> **username_1**: Why does it matter to you that the name the script gives each host has underscores for non-alphanumeric characters?  
> **username_2**: This seems to be a very specific tool-centric question. There is ServerFault for that, and its on-topic there http://serverfault.com/help/on-topic. Not sure how on-topic here, if at all.  
> **username_0**: @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 ?  

---

## 2 answers

### Answer by username_0 on 2017-03-04. Score: 5 | Accepted answer

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

> **Comments:**
> **username_3**: Alas, I am seeing the same behavior, and commenting out hostname_variable doesn't correct it.  
> **username_3**: 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.  
> **username_5**: 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 }}"  

---

### Answer by username_3 on 2018-06-14. Score: 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?

> **Comments:**
> **username_4**: Sounds like a caching “issue”. Have you tried to alter the ‘cache_max_age’ parameter in ec2.ini?  
> **username_3**: You're probably completely right. I was just looking at that today, actually. You can run "./ec2.py --refresh-cache".  

---

