I am receiving below error if using set_fact and if-else statement in my playbook
FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'hostname'. 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'hostname'nnThe error appears to be in '/runner/project/playbooks/Stack_Status.yml': line 148, column 7, but maynbe elsewhere in the file depending on the exact syntax problem.nnThe offending line appears to be:nnn - name: Write report datan ^ heren"}
The piece of code having issue is here:
- name: Set final stack version fact
set_fact:
stack_version: >
{% if composer_stack is defined and composer_stack != 'Stack not deployed' %}
{{ composer_stack }}
{% elif fleet_agent_stack is defined and fleet_agent_stack != 'Stack not deployed' %}
{{ fleet_agent_stack }}
{% else %}
V3 Stack not deployed
{% endif %}
- name: Gather server report
set_fact:
server_report: >
{
"hostname": "{{ inventory_hostname }}",
"stack_version": "{{ stack_version | default('N/A') }}"
}
I am expecting to either display the version of composer if its running, else print version of fleet-manager and both are not running display Stack not deployed