Tags in loop

Hi dear,

I need create tag in my role, this example:

vars/main.yml
name_variable:
    tags:
       key1: value1
       key2: value2

in tasks
taks/main.yml

- name: name my task
  user: name
  tags:
     tags from vars

how can create this tags?

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.

Hi,

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

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.