I have two variable definition files as follows
vars.yml
aws_common_tags:
Project: "{{ project_name }}"
Application: "{{ application_name }}"
Region: "{{ aws_region }}"
Ansible: "Yes"
instance.yml
ec2_instance_tags:
environment_name: dev
Now in task.yml I am trying to create aws ec2 instance with all tags but its not working.
ec2:
key_name: "{{ keypair_name }}"
instance_type: "{{ ec2_instance_type }}"
instance_tags: "{{ aws_common_tags + ec2_instance_tags }}"
We are getting the following error:
"tags": {
"Ansible": "Yes",
"Application": "webserver",
"Project": "document_upload",
"Region": "us-west-2"
},
fatal: [localhost]: FAILED! => {
"msg": "Unexpected templating type error occurred on ({{ aws_common_tags + ec2_instance_tags }}): unsupported operand type(s) for +: 'dict' and 'dict'" }
Thanks
It's possible combine dictionaries. For example
The concatenation "
+
" would work with lists or strings that are treated as lists.