Ansible条件语句计算不正确

Ansible条件语句计算不正确,ansible,conditional,ansible-2.x,Ansible,Conditional,Ansible 2.x,我有一个ansible playbook,其中包含两个任务,用于检查目录中今天创建的文件,并将它们保存在文件中。我正在对文件的长度进行比较,并根据长度是否为0打印出两条不同的消息 代码如下: - name: Grabbing all of the files that were created today shell: find /home/user/empty_directory -maxdepth 1 -daystart -ctime 0 -print regist

我有一个ansible playbook,其中包含两个任务,用于检查目录中今天创建的文件,并将它们保存在
文件中。我正在对
文件的长度进行比较,并根据长度是否为0打印出两条不同的消息

代码如下:

  - name: Grabbing all of the files that were created today
    shell: find /home/user/empty_directory  -maxdepth 1  -daystart -ctime 0  -print
    register: files

  - debug: var=files.stdout

  - debug: msg="The directory isn't empty"
    when: files|length != 0

  - debug: msg="The directory is empty"
    when: files|length == 0
以下是输出:

  TASK [debug]
 ok: [server] => {
 "changed": false, 
 "files.stdout": ""
 }

 TASK [debug] 
 ok: [server] => {
"changed": false, 
"msg": "The directory isn't empty"
 }

TASK [debug] 
skipping: [server] => {"changed": false, "skip_reason": "Conditional result was False", "skipped": true}
我是否犯了一个错误,导致条件句的计算不正确?因为基于输出的
文件实际上是空的

我在没有
| length
的情况下尝试了它,并对
文件==“”
文件进行了比较!=“”
,得到了相同的结果


如有任何建议,我们将不胜感激

您正在检查
文件|长度
而不是
文件.stdout |长度
。请注意,
files
是一个包含一些其他元素的字典,因此它肯定不是空的

您正在检查的是
files | length
,而不是
files.stdout | length
。请注意,
文件
还包含一些其他变量,因此肯定不是empty@SztupY-谢谢你的帮助!你的建议奏效了。如果你把它作为答案贴出来,我就投赞成票