merge two sets of AWS tags?

6 views
Skip to first unread message

Karl Auer

unread,
May 20, 2018, 11:27:56 PM5/20/18
to Ansible Project
I am clearly having a brain failure, but I can't figure out how to merge two sets of AWS tags.

AWS tags are generally defined as a variable (or attribute in a module) something like this:

tags:
   name1: value1
   name2: value2

So I will generally have some standard tags set up in a variable like this:

standard_tags:
   Name: AServer
   CostCentre: Operations

Then I generate some extra tags, so I have another variable somewhere like this:

extra_tags:
   fred: wilma
   barney: betty

How can I get one variable that looks like this:

all_tags:
   Name: AServer
   CostCentre: Operations
       fred: wilma
   barney: betty

?

Regards, K.

Kai Stian Olstad

unread,
May 21, 2018, 4:03:46 AM5/21/18
to ansible...@googlegroups.com
On 21.05.2018 05:27, Karl Auer wrote:
> So I will generally have some standard tags set up in a variable like
> this:
>
> standard_tags:
> Name: AServer
> CostCentre: Operations
>
> Then I generate some extra tags, so I have another variable somewhere
> like
> this:
>
> extra_tags:
> fred: wilma
> barney: betty
>
> How can I get one variable that looks like this:
>
> all_tags:
> Name: AServer
> CostCentre: Operations
> fred: wilma
> barney: betty

I assume fred: is just indented incorrectly so you are looking for the
combine filter.

- set_fact:
all_tags: '{{ standard_tags | combine(extra_tags) }}'

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages