--- - name: Pre-deployment tagging block: - name: Gather tags set_fact: tag_exist: "{{ tags }}" tag_append: "['active-deployment']" - name: Merge tags set_fact: tag_merged: "{{ tag_merged + [item] }}" with_items: - "{{ tag_exist }}" - "{{ tag_append }}" - name: Construct body for tagging set_fact: body1: ' {% for tag in tag_merged %}{% if loop.last %}{"slug": "{{ tag }}"}{% else %}{"slug": "{{ tag }}"},{% endif %}{% endfor %}' - name: Set pre-deployment tags ansible.builtin.uri: url: "{{ endpoint }}/virtualization/virtual-machines/{{ id }}/" client_cert: "{{ cert }}" client_key: "{{ key }}" method: PATCH return_content: yes headers: Accept: application/json Authorization: "Token {{ token }}" body_format: json body: ' {"tags": [ {{ body1 }}]}' delegate_to: localhost no_log: true