looking for an ansible script to install docker packages on the centos8 server with no internet access. I have tried the below on my test server(which has internet access) but the actual server doesn't have access to the internet and looking out for options.
---
- hosts: localhost
becomes: true
tasks:
- name: Install yum utils
yum:
name: yum-utils
state: latest
- name: Add Docker repo
get_url:
url: https://download.docker.com/linux/centos/docker-ce.repo
dest: /etc/yum.repos.d/docer-ce.repo
become: yes
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:
changed_when: false
.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 contentIf 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)