Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 :)

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

From documentation:

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

with_fileglob is a lookup plugin, so it looks for files on 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}
share|improve this answer
    
that makes so much sense now that you say it. BTW, I solved this by using [shell: chown -R newuser:newgroup /to] –  deadsven May 29 '13 at 14:12
1  
Using shell in this case is not the preferable way since you are losing idempotency. You should instead use file module and with_items –  Tom Aac May 30 '13 at 6:59
    
yes, i'd like to use the file module, but with_items does not support globs does it? listing every file in a with_items list is not really what I want –  deadsven May 30 '13 at 11:12
    
See my answer, there is what you need –  Tom Aac May 31 '13 at 14:17
    
How is shell: chown not idempotent? You can run it as many times as you like, and the state of the machine is exactly the same as if you'd just run it once. That's idempotency, no? –  Bosh Jun 12 at 21:35
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.