From ab2d368b172a5c87ffa0131c07c36248143539cf Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Mon, 10 Jun 2019 21:19:23 -0500 Subject: [PATCH] Add variable to set the docker download url The docker mirror URL can now be set using the following options, `docker_download_fqdn` and `docker_mirror_base_url`. These variables will allow folks to use this role with custom mirrors. To accomodate this change, the repo files have been moved into templates and now use the jinja2 extension. Not all supported distros have the ability to install docker using the upstream mirrors. To ensure a high degree of success a new sanity check has been added to validate the mirror url content when upstream installation has been enabled. Change-Id: Ib9d50581d0df89e36d47dd523efd1adc95fdf4ac Signed-off-by: Kevin Carter --- roles/install-docker/README.rst | 13 +++ roles/install-docker/defaults/main.yaml | 2 + .../files/docker-ce-centos.repo | 83 ------------------- .../files/docker-ce-fedora.repo | 83 ------------------- roles/install-docker/tasks/main.yaml | 9 ++ .../templates/docker-ce-centos.repo.j2 | 83 +++++++++++++++++++ .../templates/docker-ce-fedora.repo.j2 | 83 +++++++++++++++++++ .../install-docker/templates/sources.list.j2 | 2 +- roles/install-docker/vars/debian.yaml | 2 + roles/install-docker/vars/fedora.yaml | 2 + roles/install-docker/vars/redhat.yaml | 2 + 11 files changed, 197 insertions(+), 167 deletions(-) delete mode 100644 roles/install-docker/files/docker-ce-centos.repo delete mode 100644 roles/install-docker/files/docker-ce-fedora.repo create mode 100644 roles/install-docker/templates/docker-ce-centos.repo.j2 create mode 100644 roles/install-docker/templates/docker-ce-fedora.repo.j2 diff --git a/roles/install-docker/README.rst b/roles/install-docker/README.rst index cb5527df0..a83e3ad74 100644 --- a/roles/install-docker/README.rst +++ b/roles/install-docker/README.rst @@ -62,3 +62,16 @@ An ansible role to install docker and configure it to use mirrors if available. **true**. The package set is defined by default using distro specific variables. If the package set needs to be changed this option can be overridden as needed. + +.. zuul:rolevar:: docker_download_fqdn + :default: download.docker.com + + Add default option to set the docker download fqdn. + +.. zuul:rolevar:: docker_mirror_base_url + :default: https://{{ docker_download_fqdn }}/linux/{ubuntu,centos,fedora} + + By default this option sets the repository base url. This variable is + based on :zuul:rolevar:`install-docker.docker_download_fqdn`. When this + option is unset, the role will use distro specific variables which are + loaded at the time of execution. diff --git a/roles/install-docker/defaults/main.yaml b/roles/install-docker/defaults/main.yaml index 93aff9a5d..ab0d0743d 100644 --- a/roles/install-docker/defaults/main.yaml +++ b/roles/install-docker/defaults/main.yaml @@ -7,6 +7,8 @@ docker_distro_packages: "{{ _docker_distro_packages | default([]) }}" docker_upstream_distro_packages: "{{ _docker_upstream_distro_packages | default([]) }}" docker_upstream_distro_required_packages: "{{ _docker_upstream_distro_required_packages | default([]) }}" docker_update_channel: stable +docker_download_fqdn: download.docker.com +docker_mirror_base_url: "{{ _docker_mirror_base_url | default('') }}" docker_gpg_key: | -----BEGIN PGP PUBLIC KEY BLOCK----- diff --git a/roles/install-docker/files/docker-ce-centos.repo b/roles/install-docker/files/docker-ce-centos.repo deleted file mode 100644 index e45af62d5..000000000 --- a/roles/install-docker/files/docker-ce-centos.repo +++ /dev/null @@ -1,83 +0,0 @@ -[docker-ce-stable] -name=Docker CE Stable - $basearch -baseurl=https://download.docker.com/linux/centos/7/$basearch/stable -enabled=1 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/centos/gpg - -[docker-ce-stable-debuginfo] -name=Docker CE Stable - Debuginfo $basearch -baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/stable -enabled=0 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/centos/gpg - -[docker-ce-stable-source] -name=Docker CE Stable - Sources -baseurl=https://download.docker.com/linux/centos/7/source/stable -enabled=0 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/centos/gpg - -[docker-ce-edge] -name=Docker CE Edge - $basearch -baseurl=https://download.docker.com/linux/centos/7/$basearch/edge -enabled=0 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/centos/gpg - -[docker-ce-edge-debuginfo] -name=Docker CE Edge - Debuginfo $basearch -baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/edge -enabled=0 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/centos/gpg - -[docker-ce-edge-source] -name=Docker CE Edge - Sources -baseurl=https://download.docker.com/linux/centos/7/source/edge -enabled=0 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/centos/gpg - -[docker-ce-test] -name=Docker CE Test - $basearch -baseurl=https://download.docker.com/linux/centos/7/$basearch/test -enabled=0 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/centos/gpg - -[docker-ce-test-debuginfo] -name=Docker CE Test - Debuginfo $basearch -baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/test -enabled=0 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/centos/gpg - -[docker-ce-test-source] -name=Docker CE Test - Sources -baseurl=https://download.docker.com/linux/centos/7/source/test -enabled=0 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/centos/gpg - -[docker-ce-nightly] -name=Docker CE Nightly - $basearch -baseurl=https://download.docker.com/linux/centos/7/$basearch/nightly -enabled=0 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/centos/gpg - -[docker-ce-nightly-debuginfo] -name=Docker CE Nightly - Debuginfo $basearch -baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/nightly -enabled=0 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/centos/gpg - -[docker-ce-nightly-source] -name=Docker CE Nightly - Sources -baseurl=https://download.docker.com/linux/centos/7/source/nightly -enabled=0 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/centos/gpg diff --git a/roles/install-docker/files/docker-ce-fedora.repo b/roles/install-docker/files/docker-ce-fedora.repo deleted file mode 100644 index 99ad9cf20..000000000 --- a/roles/install-docker/files/docker-ce-fedora.repo +++ /dev/null @@ -1,83 +0,0 @@ -[docker-ce-stable] -name=Docker CE Stable - $basearch -baseurl=https://download.docker.com/linux/fedora/$releasever/$basearch/stable -enabled=1 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/fedora/gpg - -[docker-ce-stable-debuginfo] -name=Docker CE Stable - Debuginfo $basearch -baseurl=https://download.docker.com/linux/fedora/$releasever/debug-$basearch/stable -enabled=0 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/fedora/gpg - -[docker-ce-stable-source] -name=Docker CE Stable - Sources -baseurl=https://download.docker.com/linux/fedora/$releasever/source/stable -enabled=0 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/fedora/gpg - -[docker-ce-edge] -name=Docker CE Edge - $basearch -baseurl=https://download.docker.com/linux/fedora/$releasever/$basearch/edge -enabled=0 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/fedora/gpg - -[docker-ce-edge-debuginfo] -name=Docker CE Edge - Debuginfo $basearch -baseurl=https://download.docker.com/linux/fedora/$releasever/debug-$basearch/edge -enabled=0 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/fedora/gpg - -[docker-ce-edge-source] -name=Docker CE Edge - Sources -baseurl=https://download.docker.com/linux/fedora/$releasever/source/edge -enabled=0 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/fedora/gpg - -[docker-ce-test] -name=Docker CE Test - $basearch -baseurl=https://download.docker.com/linux/fedora/$releasever/$basearch/test -enabled=0 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/fedora/gpg - -[docker-ce-test-debuginfo] -name=Docker CE Test - Debuginfo $basearch -baseurl=https://download.docker.com/linux/fedora/$releasever/debug-$basearch/test -enabled=0 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/fedora/gpg - -[docker-ce-test-source] -name=Docker CE Test - Sources -baseurl=https://download.docker.com/linux/fedora/$releasever/source/test -enabled=0 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/fedora/gpg - -[docker-ce-nightly] -name=Docker CE Nightly - $basearch -baseurl=https://download.docker.com/linux/fedora/$releasever/$basearch/nightly -enabled=0 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/fedora/gpg - -[docker-ce-nightly-debuginfo] -name=Docker CE Nightly - Debuginfo $basearch -baseurl=https://download.docker.com/linux/fedora/$releasever/debug-$basearch/nightly -enabled=0 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/fedora/gpg - -[docker-ce-nightly-source] -name=Docker CE Nightly - Sources -baseurl=https://download.docker.com/linux/fedora/$releasever/source/nightly -enabled=0 -gpgcheck=1 -gpgkey=https://download.docker.com/linux/fedora/gpg diff --git a/roles/install-docker/tasks/main.yaml b/roles/install-docker/tasks/main.yaml index a52ff836c..5753f24e6 100644 --- a/roles/install-docker/tasks/main.yaml +++ b/roles/install-docker/tasks/main.yaml @@ -44,6 +44,15 @@ - (docker_upstream_distro_packages | length) < 1 - use_upstream_docker | bool +- name: Sanity check for upstream install mirrors + fail: + msg: >- + The variable `docker_mirror_base_url` is null, and upstream installation has been enabled. + Check your settings. + when: + - (docker_mirror_base_url | length) < 1 + - use_upstream_docker | bool + - name: Upstream block when: - use_upstream_docker | bool diff --git a/roles/install-docker/templates/docker-ce-centos.repo.j2 b/roles/install-docker/templates/docker-ce-centos.repo.j2 new file mode 100644 index 000000000..7fc8631e6 --- /dev/null +++ b/roles/install-docker/templates/docker-ce-centos.repo.j2 @@ -0,0 +1,83 @@ +[docker-ce-stable] +name=Docker CE Stable - $basearch +baseurl={{ docker_mirror_base_url }}/7/$basearch/stable +enabled=1 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg + +[docker-ce-stable-debuginfo] +name=Docker CE Stable - Debuginfo $basearch +baseurl={{ docker_mirror_base_url }}/7/debug-$basearch/stable +enabled=0 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg + +[docker-ce-stable-source] +name=Docker CE Stable - Sources +baseurl={{ docker_mirror_base_url }}/7/source/stable +enabled=0 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg + +[docker-ce-edge] +name=Docker CE Edge - $basearch +baseurl={{ docker_mirror_base_url }}/7/$basearch/edge +enabled=0 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg + +[docker-ce-edge-debuginfo] +name=Docker CE Edge - Debuginfo $basearch +baseurl={{ docker_mirror_base_url }}/7/debug-$basearch/edge +enabled=0 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg + +[docker-ce-edge-source] +name=Docker CE Edge - Sources +baseurl={{ docker_mirror_base_url }}/7/source/edge +enabled=0 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg + +[docker-ce-test] +name=Docker CE Test - $basearch +baseurl={{ docker_mirror_base_url }}/7/$basearch/test +enabled=0 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg + +[docker-ce-test-debuginfo] +name=Docker CE Test - Debuginfo $basearch +baseurl={{ docker_mirror_base_url }}/7/debug-$basearch/test +enabled=0 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg + +[docker-ce-test-source] +name=Docker CE Test - Sources +baseurl={{ docker_mirror_base_url }}/7/source/test +enabled=0 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg + +[docker-ce-nightly] +name=Docker CE Nightly - $basearch +baseurl={{ docker_mirror_base_url }}/7/$basearch/nightly +enabled=0 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg + +[docker-ce-nightly-debuginfo] +name=Docker CE Nightly - Debuginfo $basearch +baseurl={{ docker_mirror_base_url }}/7/debug-$basearch/nightly +enabled=0 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg + +[docker-ce-nightly-source] +name=Docker CE Nightly - Sources +baseurl={{ docker_mirror_base_url }}/7/source/nightly +enabled=0 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg diff --git a/roles/install-docker/templates/docker-ce-fedora.repo.j2 b/roles/install-docker/templates/docker-ce-fedora.repo.j2 new file mode 100644 index 000000000..08123c9a8 --- /dev/null +++ b/roles/install-docker/templates/docker-ce-fedora.repo.j2 @@ -0,0 +1,83 @@ +[docker-ce-stable] +name=Docker CE Stable - $basearch +baseurl={{ docker_mirror_base_url }}/$releasever/$basearch/stable +enabled=1 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg + +[docker-ce-stable-debuginfo] +name=Docker CE Stable - Debuginfo $basearch +baseurl={{ docker_mirror_base_url }}/$releasever/debug-$basearch/stable +enabled=0 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg + +[docker-ce-stable-source] +name=Docker CE Stable - Sources +baseurl={{ docker_mirror_base_url }}/$releasever/source/stable +enabled=0 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg + +[docker-ce-edge] +name=Docker CE Edge - $basearch +baseurl={{ docker_mirror_base_url }}/$releasever/$basearch/edge +enabled=0 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg + +[docker-ce-edge-debuginfo] +name=Docker CE Edge - Debuginfo $basearch +baseurl={{ docker_mirror_base_url }}/$releasever/debug-$basearch/edge +enabled=0 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg + +[docker-ce-edge-source] +name=Docker CE Edge - Sources +baseurl={{ docker_mirror_base_url }}/$releasever/source/edge +enabled=0 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg + +[docker-ce-test] +name=Docker CE Test - $basearch +baseurl={{ docker_mirror_base_url }}/$releasever/$basearch/test +enabled=0 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg + +[docker-ce-test-debuginfo] +name=Docker CE Test - Debuginfo $basearch +baseurl={{ docker_mirror_base_url }}/$releasever/debug-$basearch/test +enabled=0 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg + +[docker-ce-test-source] +name=Docker CE Test - Sources +baseurl={{ docker_mirror_base_url }}/$releasever/source/test +enabled=0 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg + +[docker-ce-nightly] +name=Docker CE Nightly - $basearch +baseurl={{ docker_mirror_base_url }}/$releasever/$basearch/nightly +enabled=0 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg + +[docker-ce-nightly-debuginfo] +name=Docker CE Nightly - Debuginfo $basearch +baseurl={{ docker_mirror_base_url }}/$releasever/debug-$basearch/nightly +enabled=0 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg + +[docker-ce-nightly-source] +name=Docker CE Nightly - Sources +baseurl={{ docker_mirror_base_url }}/$releasever/source/nightly +enabled=0 +gpgcheck=1 +gpgkey={{ docker_mirror_base_url }}/gpg diff --git a/roles/install-docker/templates/sources.list.j2 b/roles/install-docker/templates/sources.list.j2 index 7cf0b6843..a869c32bb 100644 --- a/roles/install-docker/templates/sources.list.j2 +++ b/roles/install-docker/templates/sources.list.j2 @@ -1 +1 @@ -deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_lsb.codename }} {{ docker_update_channel }} +deb [arch=amd64] {{ docker_mirror_base_url }} {{ ansible_lsb.codename }} {{ docker_update_channel }} diff --git a/roles/install-docker/vars/debian.yaml b/roles/install-docker/vars/debian.yaml index f65d51f48..111c80bb9 100644 --- a/roles/install-docker/vars/debian.yaml +++ b/roles/install-docker/vars/debian.yaml @@ -15,3 +15,5 @@ _docker_upstream_distro_packages: - containerd.io docker_distro_vars_loaded: true + +_docker_mirror_base_url: "https://{{ docker_download_fqdn }}/linux/ubuntu" diff --git a/roles/install-docker/vars/fedora.yaml b/roles/install-docker/vars/fedora.yaml index 21aa7294c..31750fcc9 100644 --- a/roles/install-docker/vars/fedora.yaml +++ b/roles/install-docker/vars/fedora.yaml @@ -14,3 +14,5 @@ _docker_upstream_distro_packages: docker_repo_template: docker-ce-centos.repo docker_distro_vars_loaded: true + +_docker_mirror_base_url: "https://{{ docker_download_fqdn }}/linux/fedora" diff --git a/roles/install-docker/vars/redhat.yaml b/roles/install-docker/vars/redhat.yaml index d49b6b071..12536b1e9 100644 --- a/roles/install-docker/vars/redhat.yaml +++ b/roles/install-docker/vars/redhat.yaml @@ -16,3 +16,5 @@ _docker_upstream_distro_packages: docker_repo_template: docker-ce-centos.repo docker_distro_vars_loaded: true + +_docker_mirror_base_url: "https://{{ docker_download_fqdn }}/linux/centos"