#!{{ 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_root = {} %}
{% for item in core__root_directories %}
{%   if hostvars[inventory_hostname]["ansible_local"]|d() and
        hostvars[inventory_hostname]["ansible_local"]["root"]|d() and
        hostvars[inventory_hostname]["ansible_local"]["root"][item.fact]|d() %}
{%     set _ = core__tpl_root.update({item.fact:
         hostvars[inventory_hostname]["ansible_local"]["root"][item.fact]}) %}
{%   else %}
{%     set _ = core__tpl_root.update({item.fact: item.path}) %}
{%   endif %}
{% endfor %}
"""

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