Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ansible stat然后与_项一起复制_Ansible - Fatal编程技术网

ansible stat然后与_项一起复制

ansible stat然后与_项一起复制,ansible,Ansible,我有一个重复的模式:: - 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

我有一个重复的模式::

- 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
...
对于一个大的列表,我如何使用和\u项来完成它

 with_items:
    - .vimrc
    - .bashrc
    - .profile
    - .gitconfig

可以使用“力”参数:

- copy: src={{ item }} dest={{ home }}/{{ item }} force=no
  with_items:
    - .vimrc
    - .bashrc
    - .profile
    - .gitconfig
Force=no仅在文件尚不存在时写入文件。
我想这正是您想要的。

您可以使用force参数:

- copy: src={{ item }} dest={{ home }}/{{ item }} force=no
  with_items:
    - .vimrc
    - .bashrc
    - .profile
    - .gitconfig
Force=no仅在文件尚不存在时写入文件。
我想这正是你想要的。

有时你甚至不想复制文件,如果文件存在于目标计算机上,即使内容不同。然后您可以这样使用(在您的场景中没有测试它,但我认为它会起作用)


希望能帮助您

有时您甚至不想复制该文件,如果目标计算机上存在该文件,即使内容不同。然后您可以这样使用(在您的场景中没有测试它,但我认为它会起作用)


希望对您有所帮助

侧注:我使用Arbab Nazar解决方案,因为在使用选项时存在cp限制:目录模式和远程src。请参阅文档侧注:我使用Arbab Nazar解决方案,因为在使用选项时存在cp限制:目录模式和远程src。见文件