Ansible: copy a directory content to another directory

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

    This I found an ideal solution for copying file from Ansible server to remote.

    copying yaml file

    - hosts: localhost
      user: {{ user }}
      connection: ssh
      become: yes
      gather_facts: no
      tasks:
       - name: Creation of directory on remote server
         file:
           path: /var/lib/jenkins/.aws
           state: directory
           mode: 0755
         register: result
       - debug: 
           var: result
    
       - name: get file names to copy
         command: "find conf/.aws -type f"
         register: files_to_copy
    
       - name: copy files
         copy:
          src: "{{ item }}" 
          dest: "/var/lib/jenkins/.aws"
          owner: {{ user }}
          group: {{ group }}
          remote_src: True
          mode: 0644
         with_items:
          - "{{ files_to_copy.stdout_lines }}"
    

提交回复
热议问题