Ansible:从本地目录获取文件列表

Ansible:从本地目录获取文件列表,ansible,Ansible,我使用ansible 1.9.4,希望从本地目录获取文件列表 在2.0版本中,有测试版,但这个版本是测试版 如何在

我使用ansible 1.9.4,希望从本地目录获取文件列表

在2.0版本中,有测试版,但这个版本是测试版


如何在<2.0中做到这一点?

不久前,我正在构建一个自动化系统,需要类似的东西-请参阅

在ansible 2.0之前,如果不使用
命令
shell
,则无法执行此操作

如果确实无法升级到ansible 2.0,请使用
命令
模块:

vars:
  directory: /path/to/dir

tasks:

  - command: "ls {{directory}}"
    register: dir_out

  - debug: var={{item}}
    with_items: dir_out.stdout_lines

这是一个在目录模板中列出所有扩展名为.j2的文件并将其传递给模块的示例

template: src="{{ item }}" dest="generated/{{ inventory_hostname }}/{{ item | basename | replace('.j2', '')}}"
  delegate_to: 127.0.0.1
  with_fileglob: templates/*.j2

现在有一个查找模块可以使用。 示例:显示名称以“ansible”开头且位置为/tmp、so/tmp/ansible的文件夹*

- name: ls -d /tmp/ansible*
  find:
    paths: /tmp
    patterns: "ansible*"
    recurse: no
    file_type: directory
  register: found_directories

- debug:
    msg: "{{ [item.path] }} "
  with_items: "{{ found_directories.files }}"

实际上Ansible 2已经不是beta版了,它已经在两天前发布了。伟大的我会试试这个,在1.9.4中是可能的。你到底想做什么?我想列出一个目录来发送远程主机上的每个文件,并使用iThanks进行特定的操作。我考虑过这个模块,但我觉得它很难看。但是,如果这是唯一的解决方案,那就让我们走吧。因为我想要一个剧本,从本地/ansible主机获取文件列表,并针对远程主机执行任务,所以我需要委托给:localhost。。。根据@user43731示例