I could not understand something from the examples in the documentation - how can I copy a file from a remote server to a local server and vice versa? There are copy and fetch modules, for example. Here I am writing in the playbook:
- name: Copy file from remote host to local machine fetch: src=/tmp/somefile dest=/tmp/fetched(взято из доки) How to specify ansible, from which host I want to copy the file? Well, respectively, when copying to a remote host, where to specify this remote host?
PS I figured it out a bit: To copy a file from a remote host to a local host:
- hosts: localhost vars_files: - config.yml tasks: - include: ../share/dev.yml - name: Get file from remote fetch: src="{{ remote_sources_path }}/test.txt" dest="backup" delegate_to: '{{ remote_host }}' tags: fetch The test.txt file will be in the directory ./backup/localhost / {{remote_sources_path}}
Copy from local to remote:
- name: Send file to remote copy: src="{{ local_sources_path }}/to_remote_test.txt" dest={{ remote_sources_path }} delegate_to: '{{ remote_host }}' tags: fetch I suspect that if you specify at the beginning - hosts: {{remote_host}} instead of localhost, you do not need to use delegate_to.