Ansible: Ec2.py Inventory script will not parse tags with an email as the value

Created on 28 Apr 2016  ·  3Comments  ·  Source: ansible/ansible

ISSUE TYPE
  • Bug Report
    ANSIBLE VERSION
ansible 2.0.1.0
CONFIGURATION
OS / ENVIRONMENT

SUMMARY

I cannot perform any ansible actions based on the "Owner" tag for machines in my environment that have an email address as the value.

STEPS TO REPRODUCE

I checked to make sure the tag values existed:

./ec2.py --list >> aws_example.json

And I can confirm "Owner" tags:

...
"ec2_tag_Owner": "infrastructure",
...
"ec2_tag_Owner": "[email protected]",
...

But when I run an ansible command to reference the hosts that use the tag, it cannot find ones with an email address as the value:

ansible -i tools/ec2.py [email protected] -m ping
EXPECTED RESULTS

Here is an example of the same command with a tag value of just "infrastructure"

ansible -i tools/ec2.py tag_Owner_infrastructure -m ping
The authenticity of host '52.53.222.209 (52.53.222.209)' can't be established.

This shows it knows of the host and tried to reach out to connect to it.

ACTUAL RESULTS
$ ansible -i tools/ec2.py [email protected] -m ping -vvvv
Using /Users/.../ansible/ansible.cfg as config file
ERROR! Specified hosts options do not match any hosts

This shows that it could not associate an instance with the Key:"Owner" and Value:"[email protected]"

bug

All 3 comments

@bhuddleston Thanks for the report, however, ec2.py is doing this "on purpose" to constrain generated group name values to ASCII alphanumeric.

Take a look at to_safe() in ec2.py: https://github.com/ansible/ansible/blob/devel/contrib/inventory/ec2.py#L1367

Your group name should be coming in as tag_Owner_it_domain_com. (you can always do debug: var=groups from your host's context to find out all groups it belongs to).

This behavior may be a little Draconian (since I've verified that we'll actually accept and work with group names with '@' and '.' in them)- feel free to file an issue or PR (or start a discussion on our mailing list/IRC) to change ec2.py's behavior.

AH! Now that I know what is going on, I tried the "_" version and it worked! Thanks for the help.

Out of curiosity, is that detailed in any documentation anywhere? I want to be sure I didn't miss something obvious.

I might reach out and see if the mailing list is receptive to it.


Brian Huddleston
Open I.T. Design (I.T. Engineer)
+1.510.460.1444 (main)
+1.510.780.2425 (fax)
[email protected]

On Apr 28, 2016, at 5:05 PM, Matt Davis [email protected] wrote:

@bhuddleston Thanks for the report, however, ec2.py is doing this "on purpose" to constrain generated group name values to ASCII alphanumeric.

Take a look at to_safe() in ec2.py: https://github.com/ansible/ansible/blob/devel/contrib/inventory/ec2.py#L1367

Your group name should be coming in as tag_Owner_it_domain_com. (you can always do debug: var=groups from your host's context to find out all groups it belongs to).

This behavior may be a little Draconian (since I've verified that we'll actually accept and work with group names with '@' and '.' in them)- feel free to file an issue or PR (or start a discussion on our mailing list/IRC) to change ec2.py's behavior.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub

Yeah, it's in the Dynamic Inventory docs page, but kinda buried down in the Tags section: "Each key/value pair is its own group of instances, again with special characters converted to underscores, in the format tag_KEY_VALUE"

Was this page helpful?
0 / 5 - 0 ratings