Data distribution modules (copy, unarchive, and get_url)

The copy module is used to transfer files from the Ansible master to the remote hosts or locally from within the remote host. This is followed by unarchive, which is an archive extractor that then transfers the files to the selected hosts. The get_url module basically downloads a file from a web location as an HTTP, HTTPS, or FTP file. The following playbook shows how each module can be used to achieve a goal:

    - name: copy file from within a remote host
copy:
src: /usr/local/script.py
dest: /home/user1/script.py
remote_src: yes
owner: user1
group: developers
mode: 0755

- name: extract an archive into remote hosts
unarchive:
src: ~/archive.tar.gz
dest: /usr/local/
owner: user1
group: developers
mode: 0755

- name: download an ansible archive to remote hosts
get_url:
url: https://github.com/ansible/ansible/archive
/v2.6.1.tar.gz
dest: /usr/local/ansible_v2.6.1.tar.gz
mode: 0777

The copy module supports having a backup option, which is very useful when copying configuration files; if there is an error, a user can always revert to the original. However, unarchive requires gtar and unzip to be installed on the master machine. All of these modules have special return values that show information about the status of the tasks.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.115.195