Ansible:评估条件时出错

Ansible: error while evaluating conditional

这本剧本我做错了什么?

$ cat check_only_centos7_tmp.yml
- hosts: myhosts
  become: yes
  gather_facts: no
  tasks:
        - name: Check Uptime
          command: uptime
          when: ansible_distribution == "CentOS"

错误:

fatal: [server.myhost.com]: FAILED! => {"msg": "The conditional check 'ansible_distribution == \"CentOS\"' failed. The error was: error while evaluating conditional (ansible_distribution == \"CentOS\"): 'ansible_distribution' is undefined\n\nThe error appears to be in '/home/user/ansible_playbooks/check_only_centos7_tmp.yml': line 11, column 11, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n        - name: Check Uptime\n          ^ here\n"}

因为你没有 gather_facts: true ansible 不知道什么是 ansible_distribution 值。它是从托管主机中发现的。