yamllint提示truthy值需为[false,true],请问truthy value指什么?
YAML规范问题:truthy value含义及修复方案
你的Ansible Playbook代码:
--- - hosts: all become: yes gather_facts: true tasks: - dnf: name=chrony state=present - service: name=chronyd state=started enabled=yes
yamllint检测结果:
3:11 warning truthy value should be one of [false, true] (truthy) 6:3 error wrong indentation: expected at least 3 (indentation) 7:52 error no new line character at the end of file (new-line-at-end-of-file)
truthy value 是什么意思?
YAML本身允许yes、no、on、off这类值被解析为布尔值,但yamllint的严格格式规则要求布尔值必须使用标准的小写true或false写法。这类非标准的布尔值写法就被称为"truthy值"——它们能被识别为真值,但不符合规范要求,因此触发警告。
你代码里第3行的become: yes就是警告来源,yes属于truthy值,不符合yamllint的布尔值格式标准。
完整修复方案
修复后的Playbook代码如下:
--- - hosts: all become: true gather_facts: true tasks: - dnf: name=chrony state=present - service: name=chronyd state=started enabled=yes
修复点说明:
- 将
become: yes改为become: true,用标准布尔值写法解决truthy警告 - 给任务列表项增加缩进(从2个空格改为4个,满足yamllint至少3个空格的要求)
- 在文件末尾添加空行,解决"无换行符结尾"的错误
内容的提问来源于stack exchange,提问作者Richard Rublev
相关产品推荐
相关产品推荐

