首页 > 解决方案 > Ansible:Jinja2 模板测试既定义了变量又不为空

问题描述

我有一个变量,我们称之为 value1,还有一个 Jinja2 模板。Jinja2 模板包括以下行:

LINE=” This string must be included this string is optional= {{ value1}}”

我需要实现的:如果 value1 是用字符串定义的——假设字符串是 OK (Value1: OK),文件应该是

LINE=” This string must be included this string is optional= OK”

如果 value1 没有定义(空 Value1: ),文件应该是

LINE=” This string must be included”

那么 Jinja2 应该如何配置呢?

标签: ansibleansible-template

解决方案



推荐阅读