Ansible: why is the file module skipping

ansible

I have an ansible 1.1 playbook where I do something like this:

- name: copy files
  sudo: True                                                                                                             
  shell: cp /from/* /to/

- name: change owner
  sudo: True
  file: path=$item owner=newuser group=newgroup
  with_fileglob: /to/*

The second task, "change owner" is always skipping. can anyone help me finding out why? is the file module skipping because the files exist? I'm stuck 🙂

Best Answer

From documentation:

Remember lookup plugins are run on the "controlling" machine:

with_fileglob is a lookup plugin, so it looks for files on the local server, the one you are running ansible-playbook from.

Here is what you can do:

- name: list files 
  action: command ls -1 /to/* 
  register: dumpfiles 

- name: change ownership 
  action: file path=$item owner=newuser group=newgroup
  with_items: ${dumpfiles.stdout_lines}