skip to Main Content

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

2

Answers


  1. You could provide the RPM from the ansible controller as part of your playbook then install it using the yum module.

    - name: Install nginx rpm from a local file
      ansible.builtin.yum:
        name: /usr/local/src/nginx-release-centos-6-0.el6.ngx.noarch.rpm
        state: present
    
    Login or Signup to reply.
  2. 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)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search