Ansible:查找文件并遍历路径 [英] Ansible: find file and loop over paths

查看:480
本文介绍了Ansible:查找文件并遍历路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Ansible角色.我想遍历文件路径列表,但出现错误:

Using an Ansible role. I would like to loop over a list of file paths, but I get an error:

template error while templating string: unexpected '/'.
String: {{/home/xyz/download.log}}

这是"list_log_files"角色的 main.yml :

This is the main.yml for the "list_log_files" role:

- name: "find logs"
  find:
    paths: /
    patterns: 'download.log'
    recurse: yes
  register: find_logs

- name: "list log files"
  debug: var="{{ item.path }}"
  with_items: "{{ find_logs.files }}"

查找返回一个数组文件",每个都是字典.词典中包含一个路径条目,这是我感兴趣的.

The find returns an array "files", each is a dictionary. The dictionary contains a path entry, which is what I am interested in.

推荐答案

debug 模块的 var 参数的正确语法(具有您的用例值)是:

The correct syntax for var argument of debug module (with the value for your use case) is:

  • 以Ansible表示法:

  • In Ansible notation:

debug: var=item.path

  • 以YAML表示法:

  • In YAML notation:

    debug:
      var: item.path
    

  • Ansible模块的用法已得到很好的记录,示例涵盖了大多数用户的需求.对于 debug 模块也是如此,因此请参阅检查示例的基本语法.

    Ansible modules' usage is fairy well documented and examples cover most users' needs. This is also true for the debug module, so refer to the examples to check the basic syntax.

    这篇关于Ansible:查找文件并遍历路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆