Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible fileglob: unable to find ... in expected paths

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:

Vagrantfile:

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/*"

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?

like image 396
Lily Mara Avatar asked Apr 10 '19 21:04

Lily Mara


1 Answers

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

https://docs.ansible.com/ansible/latest/plugins/lookup.html

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.

like image 86
sebthebert Avatar answered Nov 15 '22 10:11

sebthebert