ansible:为什么文件模块跳过?

我有一个可靠的1.1的手册,我做这样的事情:

- name: copy files sudo: True shell: cp /from/* /to/ - name: change owner sudo: True file: path=$item owner=newuser group=newgroup with_fileglob: /to/* 

第二个任务,“换主人”总是跳过。 谁能帮我找出原因? 文件模块是否因文件存在而跳过? 我卡住了:)

从文档 :

记住查找插件在“控制”机器上运行:

with_fileglob是一个查找插件,因此它会在本地服务器上查找文件,这是您正在运行ansible-playbook的文件。

以下是你可以做的事情:

 - 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} 

Ansible 1.1将recursion参数添加到文件模块中,因此您只需要为更改所有权任务执行以下操作:

 - name: change ownership action: file state=directory recurse=yes path=/to/ owner=newuser group=newgroup 

当事情发生变化时,这将会更加明显。 使用shell或命令模块将始终返回已更改的状态,即使没有实际更改。