вместо этого вы можете использовать этот синтаксис:
"{% if test_var == true %} LTE status on '{{ inventory_hostname }}' is good to go!{% else %} LTE status on '{{inventory_hostname}}' is not operational!{% endif %}"
см. Полный рабочий пример ниже, я использую логическое значение test_var
для управления выводом:
---
- hosts: localhost
gather_facts: false
vars:
test_var: true
tasks:
- debug:
msg: "{% if test_var == true %} LTE status on '{{ inventory_hostname }}' is good to go!{% else %} LTE status on '{{inventory_hostname}}' is not operational!{% endif %}"
вывод:
[http_offline@greenhat-29 tests]$ ansible-playbook test.yml
PLAY [localhost] *******************************************************************************************************************************************************************************************************
TASK [debug] ***********************************************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": " LTE status on 'localhost' is good to go!"
}
PLAY RECAP *************************************************************************************************************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0
[http_offline@greenhat-29 tests]$
РЕДАКТИРОВАТЬ:
обновлен PB с многострочной переменной:
---
- hosts: localhost
gather_facts: false
vars:
test_var: ['text line 1', 'texttttttttttt Selected = LTE more text', 'text line 3']
tasks:
- debug:
msg: "{% if test_var | join('') is search('Selected = LTE') %} LTE status on '{{ inventory_hostname }}' is good to go!{% else %} LTE status on '{{inventory_hostname}}' is not operational!{% endif %}"