我尝试使用ansible来确定路径集合中的哪一个存在,然后只对存在的路径执行一个操作(它不仅仅是下面示例中的copy
,还可以进一步编辑)。
这是我想到的-这是第二次迭代,在第二个任务中使用with_item
也无法获得任何工作。在
- name: disable plasma - identify files to act on
stat:
path: "{{ item }}"
register:
plasma_conf
with_items:
- "/usr/share/autostart/plasma-desktop.desktop"
- "/usr/share/autostart/plasma-netbook.desktop"
- "/etc/xdg/autostart/plasmashell.desktop"
- name: disable plasma - copy config locally
copy:
src: "{{ item.item }}"
dest: "/home/{{ main_user }}/.config/autostart/{{ item.item | basename }}"
with_dict:
plasma_conf.results
when:
item.stat.exists == true
复制任务失败,返回fatal: [localhost] => with_dict expects a dict
。如何基于dict
提供的dict
结构来实现这一点呢?在
感谢您的所有评论-}以前曾在多个迭代中使用过,但未能生成我想要的输出。我又回去了,用了久经考验的“废弃一切,从头开始”的方法,举了以下极简主义、自成体系的例子:
debug
和{我真的不知道有什么不同,但这是有效的-无论是在最简版本还是移植回我的代码。。。在
plasma_conf.results
是stat字典的列表。将第二个任务中的with_dict
替换为with_items
。请参见http://docs.ansible.com/ansible/playbooks_loops.html#using-register-with-a-loop,当然还有udondan建议的调试输出。在相关问题 更多 >
编程相关推荐