dockerdocker-composeansibledocker-enginedocker-ce

ansible script to install docker repo on centos server with no internet access


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

Solution

  • 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:

    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)