Ansible fileglob:无法在预期路径中找到... [英] Ansible fileglob: unable to find ... in expected paths

查看:40
本文介绍了Ansible fileglob:无法在预期路径中找到...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 ansible 删除目录中的所有文件,同时保留该目录.为此,我在任务中使用 with_fileglob 键将所有文件作为 item 变量从该目录中取出.我创建了一个最小示例来显示我的问题:

I am trying to use ansible to delete all of the files within a directory while keeping the directory. To that end, I'm using the with_fileglob key on a task to get all of the files out of that directory as item variables. I have created a minimum example that shows my issue here:

流浪文件:

Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"

  config.vm.provision :ansible do |ansible|
    ansible.limit = "all"
    ansible.playbook = "local.yml"
  end
end

local.yml:

- name: Test
  hosts: all
  become: true
  tasks:
    - name: Test debug
      debug:
        msg: "{{ item }}"
      with_fileglob:
        - "/vagrant/*"

我希望得到/vagrant 目录中每个文件的调试消息——因为这是通过 Vagrant 与 VM 同步的目录,我应该得到 Vagrantfile 和 local.yml 的消息.相反,我收到以下令人困惑的警告:

I expect to get a debug message for each file in the /vagrant directory - since this is the directory synced with the VM via Vagrant, I should get a message for the Vagrantfile, and for local.yml. Instead, I get the following confusing warning:

PLAY [Test] ********************************************************************

TASK [Gathering Facts] *********************************************************
ok: [default]

TASK [Test debug] **************************************************************
 [WARNING]: Unable to find '/vagrant' in expected paths (use -vvvvv to see
paths)


PLAY RECAP *********************************************************************
default                    : ok=1    changed=0    unreachable=0    failed=0

这里引用了哪些预期路径?我已经用多个文件全局尝试过这个,但它们都以这种方式失败,我错过了什么?

What expected paths are being referred to here? I have tried this with multiple fileglobs, and they all fail in this way, what am I missing?

推荐答案

Ansible 查找插件 在本地机器(您启动 Ansible 的地方)上执行,而不是远程机器.

Ansible lookup plugins are executed on local machine (where you launch Ansible), not remote one(s).

https://docs.ansible.com/ansible/latest/plugins/查找.html

查找插件允许 Ansible 访问来自外部来源的数据.这个除了联系外部,还可以包括读取文件系统数据存储和服务.像所有模板一样,这些插件是在 Ansible 控制机器上评估,而不是在目标/远程机器上评估.

Lookup plugins allow Ansible to access data from outside sources. This can include reading the filesystem in addition to contacting external datastores and services. Like all templating, these plugins are evaluated on the Ansible control machine, not on the target/remote.

这篇关于Ansible fileglob:无法在预期路径中找到...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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