我有一个重复的模式::
- stat: path={{ home }}/.vimrc
register: st
- copy: src=.vimrc dest={{ home }}/.vimrc
when: not st.stat.exists
- stat: path={{ home }}/.gitconfig
register: st
- copy: src=.vimrc dest={{ home }}/.gitconfig
when: not st.stat.exists
...如何使用with_items进行大列表?::
with_items:
- .vimrc
- .bashrc
- .profile
- .gitconfig发布于 2016-04-26 18:08:49
有时,您甚至不希望复制文件,如果文件存在于目标计算机上,甚至内容也不同。然后您可以这样使用(在您的场景中没有测试它,但我认为它会起作用)
- stat: path="{{ home }}/{{ item }}"
with_items:
- .vimrc
- .bashrc
- .profile
- .gitconfig
register: st
- copy: src="{{ item.item }}" dest="{{ home }}/{{ item.item }}"
with_items: "{{ st.results }}"
when: not item.stat.exists希望这对你有帮助
发布于 2016-04-26 17:05:14
您可以使用强制参数:
- copy: src={{ item }} dest={{ home }}/{{ item }} force=no
with_items:
- .vimrc
- .bashrc
- .profile
- .gitconfig只有当文件还不存在时,Force=no才会写入文件。我想这正是你想要的。
https://stackoverflow.com/questions/36870894
复制相似问题