Ansible 使用省略选项时出现问题

Ansible 使用省略选项时出现问题,ansible,arguments,jinja2,f5,omittag,Ansible,Arguments,Jinja2,F5,Omittag,我正在尝试仅在定义了我的\u int\u http时配置属性,否则我不需要它。因此,我将其编码如下: "profiles": [ "my_example.internal_tcp", "__omit_place_holder__ef8c5b99e9707c044ac07fda72fa950565f248a4" 配置文件: -“{{my_int_L4}” -“{{my_i

我正在尝试仅在定义了我的\u int\u http时配置属性,否则我不需要它。因此,我将其编码如下:

 "profiles": [
                "my_example.internal_tcp",
                "__omit_place_holder__ef8c5b99e9707c044ac07fda72fa950565f248a4"
配置文件:
-“{{my_int_L4}”
-“{{my_int_http | default(omit)}”
但是,我的执行失败,当检查实际配置中代码传递的参数时,它显示如下:

 "profiles": [
                "my_example.internal_tcp",
                "__omit_place_holder__ef8c5b99e9707c044ac07fda72fa950565f248a4"

那么,如何在传递的位置传递绝对无值呢

profiles:
      - "{{ my_int_L4 }}"
      - "{{ my_int_http | default(None) }}"
这将给您一个空字符串。您可以在遍历配置文件时添加检查

请看一下这篇文章以获得更多的理解。

Q:“如何在传递的地方传递绝对无值忽略位置保持器?”

A1:有些还可以按预期使用省略。比如说这出戏

-hosts:localhost
变量:
测试:
-“{var1 | default(false)}”
-“{var1 |默认值(省略)}”
任务:
-调试:
msg:{{'a':item}| combine({'b':true}}})
循环:“{test}}”
给予

msg:
a:错
b:是的
味精:
b:是的
作为旁注,默认值(省略)定义为字符串类型

-调试:
msg:“{{item is defined}}”
循环:“{test}}”
-调试:
msg:{{item | type_debug}}”
循环:“{test}}”
给予

任务[调试]*************************************************************
确定:[localhost]=>(item=False)=>
味精:是的
确定:[localhost]=>(项目=\u省略\u位置\u支架\u 6e56f2f992faa6e262507cb77410946ea57dc7ef)=>
味精:是的
任务[调试]*************************************************************
确定:[localhost]=>(item=False)=>
msg:bool
确定:[localhost]=>(项目=\u省略\u位置\u支架\u 6e56f2f992faa6e262507cb77410946ea57dc7ef)=>
msg:str

A2:Ansible中没有值是YAML。引述:

这通常会转换为任何本机类似null的值(例如,Perl中的undef,Python中的None)

(考虑到我的_int_L4=bob)。如果变量my_int_http默认为null而不是省略

配置文件:
-“{{my_int_L4}”
-“{{my_int_http | default(null)}”
列表配置文件将未定义

profiles:未定义变量!
改用“无”

配置文件:
-“{{my_int_L4}”
-“{{my_int_http |默认值(无)}”
变量my_int_http默认为空字符串

配置文件:
-鲍勃
- ''

另请参见中的“YAML标记和Python类型”一节。

我喜欢这些答案。通过阅读你的答案,我每天都在学习新的东西。