Ansible:将一个目录内容复制到另一个目录 [英] Ansible: copy a directory content to another directory

查看:58
本文介绍了Ansible:将一个目录内容复制到另一个目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 dist 目录的内容复制到 nginx 目录.

I am trying to copy the content of dist directory to nginx directory.

- name: copy html file
  copy: src=/home/vagrant/dist/ dest=/usr/share/nginx/html/

但是当我执行剧本时它会抛出一个错误:

But when I execute the playbook it throws an error:

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

如何复制包含另一个目录和文件的目录?

How can I copy a directory that has another directory and a file inside?

推荐答案

已解决的答案:要将目录的内容复制到另一个目录,我使用下一个:

Resolved answer: To copy a directory's content to another directory I use the next:

- name: copy consul_ui files
  command: cp -r /home/{{ user }}/dist/{{ item }} /usr/share/nginx/html
  with_items:
   - "index.html"
   - "static/"

它将两个项目都复制到另一个目录.在该示例中,其中一项是目录,而另一项不是.它完美运行.

It copies both items to the other directory. In the example, one of the items is a directory and the other is not. It works perfectly.

这篇关于Ansible:将一个目录内容复制到另一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆