【问题标题】:How to get the matched return value from find module in ansible?如何从ansible中的find模块获取匹配的返回值?
【发布时间】:2019-07-12 14:34:52
【问题描述】:

我正在运行一个查看目录的 Ansible playbook,如果大小大于 1 兆字节,则它找到了匹配项。我只是想验证它是否找到了正确的文件。但是,我很难捕获输出。我用了文档里的debug模块,还是没解决。

- hosts: node2 
  tasks: 
    - name: Recursively find /tmp files with last access time greater than 3600 seconds
      find:
        paths: /tmp/myFile/outputs
        size: 1m
        recurse: yes

    - debug:
        matched:

我收到此错误:

TASK [debug] *******************************************************************************************************************************************************************************************
fatal: [10.245.61.245]: FAILED! => {"msg": "Invalid options for debug: matched"}

【问题讨论】:

  • 嗨@robert,欢迎来到SO。如果您想在此站点上获得良好的体验,您应该知道,尽管非常欢迎初学者,但这里的大多数人都会等待您付出相当多的努力和奉献。实际上阅读您的错误消息,研究和阅读您的工具文档是其中的一部分。请查看debug module doc(您会看到matched实际上不是debug选项,而是msgvar

标签: ansible


【解决方案1】:

您可以将任务的返回值保存到变量中,然后您可以打印出该变量。

(我稍微修改了你的代码)

- hosts: node2 
  tasks: 
    - name: Recursively find /tmp files with last access time greater than 3600 seconds
      find:
        paths: /tmp
        size: 1k
        recurse: yes
      register: result

    - debug:
        var: result

如果您想更深入,这里有一些有用的链接:

希望能帮到你:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多