Software >> Automation >> Ansible >> Modules >> copy >> Examples

 

copy

online help: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html
offline help: ansible-doc copy   (run this command on the ansible control node)


## EXAMPLE 1
## PLAYBOOK

---
- name: Copy module - example 1
  hosts: all
  become: True
  vars:
    srcfile: "myscript.sh"
    srcdir: "/home/ansible"
    destdir: "/home/ansible"
    owner: "ansible"
    group: "ansible"
    perm: "0755"

  tasks:
  - name: Copy file and set ownership and permissions
    copy:
       src: "{{ srcdir }}/{{ srcfile }}"
       dest: "{{ destdir }}"
       owner: "{{ owner }}"
       group: "{{ group }}"
       mode: "{{ perm }}"

  - name: Verify file was copied
    shell: "ls -ldh {{ destdir }}/{{ srcfile }}"
    register: listing
  - debug: msg="{{ listing.stdout }}"


## OUTPUT

 


## EXAMPLE 2
##

 

References

  1. ansible.builtin plugins and modules index
  2. ansible collections index
  3. ansible loops
  4. ansible conditionals
  5. ansible playbook error handling
  6. ansible playbook tests
  7. ansible playbook blocks
  8. ansible playbook roles
  9. ansible playbook files