# add a tag while creating an EBS via ec2\_vol

**URL:** <https://forum.ansible.com/t/add-a-tag-while-creating-an-ebs-via-ec2-vol/13847>\
**Category:** Ansible Project\
**Created:** [November 5, 2013, 9:54am UTC](https://forum.ansible.com/t/add-a-tag-while-creating-an-ebs-via-ec2-vol/13847 "2013-11-05T09:54:22Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![cpatanaik](https://avatars.discourse-cdn.com/v4/letter/c/cdc98d/32.png) [@cpatanaik](https://forum.ansible.com/u/cpatanaik)\
**Post date:** [November 5, 2013, 9:54am UTC](https://forum.ansible.com/t/add-a-tag-while-creating-an-ebs-via-ec2-vol/13847/1 "2013-11-05T09:54:22Z")

</div>

Hi,

I would like to add some tags while creating new volumes using ec2\_vol module.

I saw that this feature has been implemented and merged in github issues. But I couldn’t find the documentation for it.

I would be grateful if anybody could point me to some documentation.

Thanks,  
Chinmaya

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 6, 2013, 2:05pm UTC](https://forum.ansible.com/t/add-a-tag-while-creating-an-ebs-via-ec2-vol/13847/2 "2013-11-06T14:05:16Z")

</div>

I’m actually not seeing any tag support in the ec2\_vol module.

Perhaps link me to the github ticket you saw?

---

<div class="post-metadata">

**Author:** ![willthames](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@willthames](https://forum.ansible.com/u/willthames)\
**Post date:** [November 7, 2013, 9:07am UTC](https://forum.ansible.com/t/add-a-tag-while-creating-an-ebs-via-ec2-vol/13847/3 "2013-11-07T09:07:17Z")

</div>

Tagging of volumes is supported through the ec2\_tag module.  
[http://www.ansibleworks.com/docs/modules.html#ec2-tag](http://www.ansibleworks.com/docs/modules.html#ec2-tag)

It would be nice to have both happen simultaneously but it’s definitely feasible if you register the result of running ec2\_vol.

Will

---

<div class="post-metadata">

**Author:** ![cpatanaik](https://avatars.discourse-cdn.com/v4/letter/c/cdc98d/32.png) [@cpatanaik](https://forum.ansible.com/u/cpatanaik)\
**Post date:** [November 18, 2013, 6:35am UTC](https://forum.ansible.com/t/add-a-tag-while-creating-an-ebs-via-ec2-vol/13847/4 "2013-11-18T06:35:55Z")

</div>

I saw the tag module… But when I use it with ec2\_vol.I am getting error…  
My sample playbook is

---

<div class="post-metadata">

**Author:** ![willthames](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@willthames](https://forum.ansible.com/u/willthames)\
**Post date:** [November 18, 2013, 8:55am UTC](https://forum.ansible.com/t/add-a-tag-while-creating-an-ebs-via-ec2-vol/13847/5 "2013-11-18T08:55:23Z")

</div>

I haven’t used it for a while and don’t have my working copy any more…

Can you run it with -v so that we can see the results of ec2\_vol (you may need to strip out your secret keys from the results - I recommend using environment variables for the secrets where you can). I suspect it’s something to do with ec2\_volumes.results.

You may get some more information using  
action: debug msg={{ec2\_volumes}}  
if you’re using v1.4

Will

---

<div class="post-metadata">

**Author:** ![cpatanaik](https://avatars.discourse-cdn.com/v4/letter/c/cdc98d/32.png) [@cpatanaik](https://forum.ansible.com/u/cpatanaik)\
**Post date:** [November 18, 2013, 9:03am UTC](https://forum.ansible.com/t/add-a-tag-while-creating-an-ebs-via-ec2-vol/13847/6 "2013-11-18T09:03:33Z")

</div>

When I run the playbook with -v and debug option, I get the following output.

PLAY [Create a volume] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost]

TASK: [Create an ebs volume] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {“device”: null, “volume\_id”: “vol-XXXXXX”}

TASK: [Print out the volume ids] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {“msg”: “{udevice:”}

TASK: [Tag the volume] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [localhost] =\> One or more undefined variables: ‘str object’ has no attribute ‘volume\_id’

FATAL: all hosts have already failed – aborting

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
to retry, use: --limit @/root/cv.retry

localhost : ok=3 changed=0 unreachable=1 failed=0

Thanks,

---

<div class="post-metadata">

**Author:** ![willthames](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@willthames](https://forum.ansible.com/u/willthames)\
**Post date:** [November 18, 2013, 9:14am UTC](https://forum.ansible.com/t/add-a-tag-while-creating-an-ebs-via-ec2-vol/13847/7 "2013-11-18T09:14:17Z")

</div>

Comparing how ec2 and ec2\_vol process their results, I suspect this is a bug in ec2\_vol - it’s just printing the json results, not running module.exit\_json with the results. I was sure I had this working although I went over to another approach (creating the volume at instance creation time and tagging it then, which I’m still hoping to get accepted at some point - [https://github.com/ansible/ansible/pull/4534](https://github.com/ansible/ansible/pull/4534))

If you raise this as a bug on github I can look at fixing how this works - hopefully someone will accept it relatively quickly.

Will

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 20, 2013, 4:04am UTC](https://forum.ansible.com/t/add-a-tag-while-creating-an-ebs-via-ec2-vol/13847/8 "2013-11-20T04:04:02Z")

</div>

Sorry about that, we’re still actively working through a pile of pull requests.

A seperate fix for a print issue could be more quickly merged, but we’ll get there.

Dented a ginormous chunk this release thanks to bringing the community team up by an extra developer!

---

<div class="post-metadata">

**Author:** ![willthames](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@willthames](https://forum.ansible.com/u/willthames)\
**Post date:** [November 20, 2013, 11:00am UTC](https://forum.ansible.com/t/add-a-tag-while-creating-an-ebs-via-ec2-vol/13847/9 "2013-11-20T11:00:09Z")

</div>

Ok, this was a red herring, apologies. There is nothing actually wrong with using print json.dumps rather than module.exit\_json (I tested both versions)

You need to use  
debug msg=“{{ec2\_volumes}}”

(note the quotes around the variable)

Perhaps the problem is the use of the with\_items with a single result (obviously with\_items would work with a one element array, but may well not work with a single result)

I would try the following (note that I rename the register variable to reflect that it is a single result):

- name: Create an ebs volume  
local\_action: ec2\_vol volume\_size=100 aws\_access\_key={{aa\_key}} aws\_secret\_key={{as\_key}} zone=us-east-1a region=us-east-1  
register: ec2\_volume

- name: Tag the volume  
local\_action: ec2\_tag resource={{ec2\_volume.volume\_id}} region=us-east-1 state=present aws\_access\_key={{aa\_key}} aws\_secret\_key={{as\_key}}  
args:  
tags:  
name: test

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 20, 2013, 2:19pm UTC](https://forum.ansible.com/t/add-a-tag-while-creating-an-ebs-via-ec2-vol/13847/10 "2013-11-20T14:19:00Z")

</div>

When in doubt, using 1.4:

- debug: var=what\_variable\_I\_registered

will tell you the exact structure

---

<div class="post-metadata">

**Author:** ![cpatanaik](https://avatars.discourse-cdn.com/v4/letter/c/cdc98d/32.png) [@cpatanaik](https://forum.ansible.com/u/cpatanaik)\
**Post date:** [November 21, 2013, 6:13am UTC](https://forum.ansible.com/t/add-a-tag-while-creating-an-ebs-via-ec2-vol/13847/11 "2013-11-21T06:13:53Z")

</div>

Thanks…That solved the issue.
