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
- ansible.builtin plugins and modules index
- ansible collections index
- ansible loops
- ansible conditionals
- ansible playbook error handling
- ansible playbook tests
- ansible playbook blocks
- ansible playbook roles
- ansible playbook files
|