关于布尔类型转换的 Ansible 警告
Ansible warning about boolean type conversion
我有 Ansible 的这个片段:
- name: check for reboot request
stat:
path: /var/run/reboot-required
register: reboot_request
- name: reboot if requested
reboot:
reboot_timeout: 180
test_command: whoami
when: reboot_request.stat.exists
...生成此警告:
[WARNING]: The value True (type bool) in a string field was converted to
u'True' (type string). If this does not look like what you expect, quote the
entire value to ensure it does not change.
我发现错误消息不是很有帮助。什么是正确的语法?
我是 运行 MacOS 10.15.4 上的 Ansible 2.9.7,目标机器是 Ubuntu 18.04.3,使用 Vagrant 2.2.7 构建,如果有任何问题的话! :)
编辑:这是我的全部剧本
---
- hosts: all
become: yes
tasks:
- name: Ubuntu Update and Upgrade
apt:
upgrade: yes
update_cache: yes
cache_valid_time: 3600
- name: check for reboot request
stat:
path: /var/run/reboot-required
register: reboot_request
- name: reboot if requested
reboot:
reboot_timeout: 180
test_command: whoami
when: reboot_request.stat.exists
看来问题出在这里
- name: Ubuntu Update and Upgrade
apt:
upgrade: yes
update_cache: yes
cache_valid_time: 3600
如果您查看 apt 文档 (https://docs.ansible.com/ansible/latest/modules/apt_module.html),您会发现 upgrade
键需要一个字符串而不是布尔值。
Choices:
dist
full
no ←
safe
yes
所以你必须这样写
- name: Ubuntu Update and Upgrade
apt:
upgrade: "yes"
update_cache: yes
cache_valid_time: 3600
删除警告
我有 Ansible 的这个片段:
- name: check for reboot request
stat:
path: /var/run/reboot-required
register: reboot_request
- name: reboot if requested
reboot:
reboot_timeout: 180
test_command: whoami
when: reboot_request.stat.exists
...生成此警告:
[WARNING]: The value True (type bool) in a string field was converted to
u'True' (type string). If this does not look like what you expect, quote the
entire value to ensure it does not change.
我发现错误消息不是很有帮助。什么是正确的语法?
我是 运行 MacOS 10.15.4 上的 Ansible 2.9.7,目标机器是 Ubuntu 18.04.3,使用 Vagrant 2.2.7 构建,如果有任何问题的话! :)
编辑:这是我的全部剧本
---
- hosts: all
become: yes
tasks:
- name: Ubuntu Update and Upgrade
apt:
upgrade: yes
update_cache: yes
cache_valid_time: 3600
- name: check for reboot request
stat:
path: /var/run/reboot-required
register: reboot_request
- name: reboot if requested
reboot:
reboot_timeout: 180
test_command: whoami
when: reboot_request.stat.exists
看来问题出在这里
- name: Ubuntu Update and Upgrade
apt:
upgrade: yes
update_cache: yes
cache_valid_time: 3600
如果您查看 apt 文档 (https://docs.ansible.com/ansible/latest/modules/apt_module.html),您会发现 upgrade
键需要一个字符串而不是布尔值。
Choices:
dist
full
no ←
safe
yes
所以你必须这样写
- name: Ubuntu Update and Upgrade
apt:
upgrade: "yes"
update_cache: yes
cache_valid_time: 3600
删除警告