#!{{ ansible_python['executable'] }}

# {{ ansible_managed }}

from __future__ import print_function
from json import loads, dumps
from sys import exit

# Workaround to allow Jinja template inside of a Python script
"""
{% set core__tpl_tags = [] %}
{% if not core__reset_tags|d(False) %}
{%   if ansible_local|d() and ansible_local.tags|d() %}
{%     for element in ansible_local.tags %}
{%       set _ = core__tpl_tags.append(element) %}
{%     endfor %}
{%   endif %}
{% endif %}
{% set core__tpl_tags_list = (core__tpl_tags + core__tags|d([])
                              + core__group_tags|d([])
                              + core__host_tags|d([]))
                             | difference(core__remove_tags|d([])) %}
{% if core__static_tags|d() %}
{%   set core__tpl_tags_list = core__static_tags|d([])
                               | difference(core__remove_tags|d([])) %}
{% endif %}
"""

output = loads('''{{ core__tpl_tags_list | sort | unique | to_nice_json }}''')
print(dumps(output, sort_keys=True, indent=4))
