Asi*_*mez 38 ansible ansible-2.x
我试图将dist目录的内容复制到nginx目录.
我写下一个:
- name: copy html file
copy: src=/home/vagrant/dist/ dest=/usr/share/nginx/html/
Run Code Online (Sandbox Code Playgroud)
但是当我执行playbook时会抛出一个错误:
TASK [NGINX : copy html file] **************************************************
fatal: [172.16.8.200]: FAILED! => {"changed": false, "failed": true, "msg": "attempted to take checksum of directory:/home/vagrant/dist/"}
Run Code Online (Sandbox Code Playgroud)
它有一个复制目录的错误?如何复制其他目录和文件中的目录内容?
有帮助吗?谢谢
Aid*_*man 37
您可以使用同步模块.文档中的示例:
# Synchronize two directories on one remote host.
- synchronize:
src: /first/absolute/path
dest: /second/absolute/path
delegate_to: "{{ inventory_hostname }}"
Run Code Online (Sandbox Code Playgroud)
这具有额外的好处,它对于大/多个文件将更有效.
Asi*_*mez 28
解决了答案:要将目录的内容复制到另一个目录,我使用下一个:
- name: copy consul_ui files
command: cp -r /home/{{ user }}/dist/{{ item }} /usr/share/nginx/html
with_items:
- "index.html"
- "static/"
Run Code Online (Sandbox Code Playgroud)
它将两个项目复制到另一个目录.在该示例中,其中一个项目是目录而另一个项目不是.它完美地运作.
hel*_*loV 20
Ansible Copy模块默认将文件/ dirs从控制机器复制到远程机器.如果要在远程计算机中复制文件/目录,并且如果您有Ansible 2.0,请设置remote_src为yes
- name: copy html file
copy: src=/home/vagrant/dist/ dest=/usr/share/nginx/html/ remote_src=yes directory_mode=yes
Run Code Online (Sandbox Code Playgroud)
and*_*mel 12
要将目录的内容复制到另一个目录,您可以使用 ansiblescopy模块:
- name: Copy content of directory 'files'
copy:
src: files/ # note the '/' <-- !!!
dest: /tmp/files/
Run Code Online (Sandbox Code Playgroud)
如果 (src!) path 是一个目录,它将被递归复制...
...如果 path 以“/”结尾,则只有该目录的内部内容被复制到 destination。
...如果它不以“/”结尾,则复制包含所有内容的目录本身。
我发现复制文件夹内容而不复制文件夹本身的最简单的解决方案是使用以下内容:
- name: Move directory contents
command: cp -r /<source_path>/. /<dest_path>/
Run Code Online (Sandbox Code Playgroud)
这解决了@ surfer190的后续问题:
嗯,如果你想复制整个内容怎么办?我注意到*不起作用 - 冲浪190 2016年7月23日7:29
*是一个shell glob,它依赖于你的shell 在运行之前枚举文件夹中的所有文件cp,而.直接指示cp获取目录内容(参见https://askubuntu.com/questions/86822/how-can- i-copy-a-folder-of-a-folder-to-another-folder-in-a-different-directo)
| 归档时间: |
|
| 查看次数: |
119680 次 |
| 最近记录: |