Similar to: Set fact with dynamic key name in ansible
I have a custom plugin that returns a dictionary. I'd like to set the dict as multiple facts on a host but set-fact doesn't act as expected. Whats the correct way to set multiple facts from a template expression in Ansible?
This does not work.
# Should set "name", "uuid"
- set_fact: "{{ plugin_returns_a_dict(inventory_hostname) }}"
# Evaluates to false
- assert:
that: name is defined
This does work.
# Should set "name", "uuid"
- with_dict: "{{ plugin_returns_a_dict(inventory_hostname) }}"
set_fact: { "{{ item.key }}": "{{ item.value }}" }
# Evaluates to true
- assert:
that: name is defined