5
ansible自定义变量在when中判断
source link: https://blog.51cto.com/u_13236892/5714631
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
ansible自定义变量在when中判断
精选 原创1、hosts中定义
在hosts自定义模块中新添加了一个字段
vi hosts
[test]
10.10.10.10 iswar=true
[all:vars]
ansible_ssh_port=22
ansible_ssh_user=root
ansible_ssh_pass=123456
iswar这个变量想在yaml中进行when判断
方法一:
when: "{{ iswar }} == true"
这个样子可以使用,但是会报一个warning
"[WARNING] when statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{ iswar }} == true"
方法二:
when: iswar == "true"
但是下面两种方式就不行,这两种都不会进行判断
when: iswar == true
when: "iswar == true"
vi hosts
[test]
10.10.10.10 iswar=true
[all:vars]
ansible_ssh_port=22
ansible_ssh_user=root
ansible_ssh_pass=123456
iswar这个变量想在yaml中进行when判断
方法一:
when: "{{ iswar }} == true"
这个样子可以使用,但是会报一个warning
"[WARNING] when statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{ iswar }} == true"
方法二:
when: iswar == "true"
但是下面两种方式就不行,这两种都不会进行判断
when: iswar == true
when: "iswar == true"
2、在vars_files中定义
cat test_module/test_module.yaml
iswar: true
vars_files: test_module/test_module.yaml
iswar这个变量想在yaml中进行when判断
方法一:
when: "{{ iswar }} == true"
还是会报那个warning
方法二:
when: iswar == true
#注意此处true不能有"",如果有""则不判断
其他方式几乎都不判断
iswar: true
vars_files: test_module/test_module.yaml
iswar这个变量想在yaml中进行when判断
方法一:
when: "{{ iswar }} == true"
还是会报那个warning
方法二:
when: iswar == true
#注意此处true不能有"",如果有""则不判断
其他方式几乎都不判断
- 赞
- 收藏
- 评论
- 分享
- 举报
上一篇:文本编码格式导致中文乱码
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK