Ansible: copy a directory content to another directory

前端 未结 12 1137
青春惊慌失措
青春惊慌失措 2020-12-24 00:25

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/
         


        
12条回答
  •  再見小時候
    2020-12-24 01:30

    The simplest solution I've found to copy the contents of a folder without copying the folder itself is to use the following:

    - name: Move directory contents
      command: cp -r //. //
    

    This resolves @surfer190's follow-up question:

    Hmmm what if you want to copy the entire contents? I noticed that * doesn't work – surfer190 Jul 23 '16 at 7:29

    * is a shell glob, in that it relies on your shell to enumerate all the files within the folder before running cp, while the . directly instructs cp to get the directory contents (see https://askubuntu.com/questions/86822/how-can-i-copy-the-contents-of-a-folder-to-another-folder-in-a-different-directo)

提交回复
热议问题