If only the target server isn't connected to internet, you can get the file from the controller and push it to the target:
- name: Get Docker repo definition locally
ansible.builtin.get_url:
url: https://download.docker.com/linux/centos/docker-ce.repo
dest: /tmp/docer-ce.repo
changed_when: false
delegate_to: localhost
run_once: true
- name: Copy the repo file to target(s)
ansible.builtin.copy:
src: /tmp/docer-ce.repo
dest: /etc/yum.repos.d/docer-ce.repo
become: yes
In the above:
- I considered getting the ref file from url to controller being a non-event as far as idempotence is concerned, hence why the
changed_when: false
.
- The copy task will report
change
if the file has to be created or was modified if it differs on target from the fetched reference.*
run_once: true
ensures the file is fetched only once whatever the number of target hosts in your play loop. The copy task will run for each target and push the file with the same content
If both the controller and target are not connected to internet, you will have to get the repo file on the controller somehow before copying (and maintain it over time)