Ansible: copy a directory content to another directory

前端 未结 12 1133
青春惊慌失措
青春惊慌失措 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:10

    I got involved whole a day, too! and finally found the solution in shell command instead of copy: or command: as below:

    - hosts: remote-server-name
      gather_facts: no
      vars:
        src_path: "/path/to/source/"
        des_path: "/path/to/dest/"
      tasks:
      - name: Ansible copy files remote to remote
        shell: 'cp -r {{ src_path }}/. {{ des_path }}'
    

    strictly notice to: 1. src_path and des_path end by / symbol 2. in shell command src_path ends by . which shows all content of directory 3. I used my remote-server-name both in hosts: and execute shell section of jenkins, instead of remote_src: specifier in playbook.

    I guess it is a good advice to run below command in Execute Shell section in jenkins:

    ansible-playbook  copy-payment.yml -i remote-server-name
    

提交回复
热议问题