tag_Name issue with ec2.py

551 views
Skip to first unread message

ji...@pristine.io

unread,
Nov 8, 2014, 8:59:41 PM11/8/14
to ansible...@googlegroups.com
Hi all. I am running into an issue and I am having trouble figuring out the problem. 

I am trying to set up Ansible with the ec2.py script replacing /etc/ansible/hosts with ec2.py and I am attempting to list my instances with tag_Name.

I am running Ansible inside an Amazon VPC so I have the following settings in ec2.ini

destination_variable = private_dns_name
vpc_destination_variable = private_ip_address

When I run ec2.py --list it works:

: ./ec2.py --list
{
  "_meta": {
    "hostvars": {
      "10.30.15.0": {
        "ec2__in_monitoring_element": false,
        "ec2_ami_launch_index": "0",

If I change vpc_destination_variable to other things like id or image_id it works. But if I set it to tag_Name I get the following error:

AttributeError: 'Instance' object has no attribute 'tag_Name'

I see tag_Name as an attribute when I do ec2.py --host HOST 

What am I missing here? I am using Ansible 1.7.2

Thanks!

Michael Peters

unread,
Nov 10, 2014, 10:25:55 AM11/10/14
to ansible...@googlegroups.com
This is because tags are not properties on the instance objects. I do
agree that it's weird that you can only pick properties of the
underlying python object for the destination variable.
The list of those properties is available here:
http://docs.pythonboto.org/en/latest/ref/ec2.html#module-boto.ec2.instance

I think it could be improved if instance it waited until all the data
was gathered and then allowed you to pick anything that was a property
in the json hash instead.
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/6c39f599-3659-419e-a951-5e37cc562c6a%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

ji...@pristine.io

unread,
Nov 10, 2014, 12:14:33 PM11/10/14
to ansible...@googlegroups.com
Thanks for the reply. I wasn't able to update this earlier as the post was being moderated. I was trying to figure out how to group my instances like you would with the standard /etc/ansible/hosts but after RTFM'ing further I discovered I could group them by adding a tag named class and calling those in my playbooks with tag_class_groupname. I started another post with a similar question about how to display tag_Name during the playbook runs but I'll wait for that post to be approved and update that one as well.

Now I would like to figure out how to 

Chris Church

unread,
Nov 13, 2014, 8:15:17 AM11/13/14
to ansible...@googlegroups.com
There is an open PR for using tags as names: https://github.com/ansible/ansible/pull/7601

Until this one is merged, you could try applying those changes to your copy of ec2.py.


ji...@pristine.io

unread,
Nov 13, 2014, 8:30:26 AM11/13/14
to ansible...@googlegroups.com
Hi Chris,

Thanks! I'll give this a try.

-Jimmy
Reply all
Reply to author
Forward
0 new messages