# Tags in loop

**URL:** <https://forum.ansible.com/t/tags-in-loop/29561>\
**Category:** Ansible Project\
**Created:** [January 29, 2019, 12:25pm UTC](https://forum.ansible.com/t/tags-in-loop/29561 "2019-01-29T12:25:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafael\_Tomelin](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Rafael\_Tomelin](https://forum.ansible.com/u/Rafael_Tomelin)\
**Post date:** [January 29, 2019, 12:25pm UTC](https://forum.ansible.com/t/tags-in-loop/29561/1 "2019-01-29T12:25:37Z")

</div>

Hi dear,

I need create tag in my role, this example:

vars/main.yml  
name\_variable:  
&nbsp;&nbsp;&nbsp;&nbsp;tags:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;key1: value1  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;key2: value2

in tasks  
taks/main.yml

- name: name my task  
&nbsp;&nbsp;user: name  
&nbsp;&nbsp;tags:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tags from vars

how can create this tags?

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [January 29, 2019, 9:36pm UTC](https://forum.ansible.com/t/tags-in-loop/29561/2 "2019-01-29T21:36:39Z")

</div>

What kind of tag? Do you mean an ansible tag, or a tag for e.g. Amazon resources?

If you mean Ansible tags, I do not know.

If you mean AWS tags, most resource modules provide a “tags” attribute, if the resource supports tags. Some resources (generally those with IDs) can be tagged using the ec2\_tag module.

Regards, K.

---

<div class="post-metadata">

**Author:** ![Rafael\_Tomelin](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Rafael\_Tomelin](https://forum.ansible.com/u/Rafael_Tomelin)\
**Post date:** [January 29, 2019, 11:27pm UTC](https://forum.ansible.com/t/tags-in-loop/29561/3 "2019-01-29T23:27:15Z")

</div>

Hi,

This tag in ansible. I need set key and value (- key: value), but in variable.

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [January 29, 2019, 11:44pm UTC](https://forum.ansible.com/t/tags-in-loop/29561/4 "2019-01-29T23:44:29Z")

</div>

Great! Then I just told you how to do it.

vars:  
mytags:  
fred: frederick  
rod: roderick

- module\_whatever:  
[…]  
tags: “{{ mytags }}”

[…]

Or if you have the IDs of the resources you want to tag, use the ec2\_tag module.

Regards, K.
