关于布尔类型转换的 Ansible 警告

gue*_*est 0 ubuntu vagrant ansible

我有这个 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
Run Code Online (Sandbox Code Playgroud)

...产生此警告:

[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.
Run Code Online (Sandbox Code Playgroud)

我发现错误消息不是很有帮助。什么是正确的语法?

我在 MacOS 10.15.4 上运行 Ansible 2.9.7,目标机器是使用 Vagrant 2.2.7 构建的 Ubuntu 18.04.3,如果有的话!:)

编辑:这是我的整个剧本

---
- 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

Run Code Online (Sandbox Code Playgroud)

pap*_*pey 5

看起来问题出在这里

  - name: Ubuntu Update and Upgrade 
    apt:
      upgrade: yes
      update_cache: yes
      cache_valid_time: 3600
Run Code Online (Sandbox Code Playgroud)

如果您查看 apt 文档(https://docs.ansible.com/ansible/latest/modules/apt_module.html),您会发现upgrade密钥需要一个字符串而不是 bool。

Choices:
dist
full
no ?
safe
yes
Run Code Online (Sandbox Code Playgroud)

所以你必须写这个

  - name: Ubuntu Update and Upgrade 
    apt:
      upgrade: "yes"
      update_cache: yes
      cache_valid_time: 3600
Run Code Online (Sandbox Code Playgroud)

删除警告