I am receiving the below error if I use set_fact and if-else statements 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') }}"
}
name: Write report data
shell: |
echo ""{{ server_report.hostname }}","{{ server_report.stack_version }}"" >> "{{ report_file }}"
I am expecting to either display the version of Composer if it is running, or print the version of Fleet-Manager and both are not running display, Stack is not deployed.
I am expecting to either display the version of Composer if it is running, or print the version of Fleet-Manager and both are not running display, Stack is not deployed.