From fb41492e4ac8ef5979c96a1e4d8f47b3ed923dca Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Tue, 11 Jun 2019 16:56:30 -0500 Subject: [PATCH] Isolate installation mode The role variables were making generalizations on distro package and installation methods. This change further breaks things out, now explicitly supporting ubuntu, debian, fedora, and redhat(centos). Change-Id: Ib1749721b32b21ba1ab661a64097d79037e416f3 Signed-off-by: Kevin Carter --- roles/install-docker/handlers/main.yml | 4 +- roles/install-docker/tasks/docker-distro.yaml | 14 +++++ roles/install-docker/tasks/docker-setup.yaml | 16 ++++++ .../install-docker/tasks/docker-upstream.yaml | 13 +++++ roles/install-docker/tasks/main.yaml | 51 ++----------------- roles/install-docker/tasks/upstream-apt.yaml | 13 ++--- .../tasks/upstream-package-installation.yaml | 8 +++ roles/install-docker/tasks/upstream-yum.yaml | 11 +--- roles/install-docker/vars/debian.yaml | 2 +- roles/install-docker/vars/fedora.yaml | 2 +- roles/install-docker/vars/opensuse.yaml | 7 +++ roles/install-docker/vars/redhat.yaml | 2 +- roles/install-docker/vars/ubuntu.yaml | 19 +++++++ 13 files changed, 92 insertions(+), 70 deletions(-) create mode 100644 roles/install-docker/tasks/docker-distro.yaml create mode 100644 roles/install-docker/tasks/docker-setup.yaml create mode 100644 roles/install-docker/tasks/docker-upstream.yaml create mode 100644 roles/install-docker/tasks/upstream-package-installation.yaml create mode 100644 roles/install-docker/vars/ubuntu.yaml diff --git a/roles/install-docker/handlers/main.yml b/roles/install-docker/handlers/main.yml index fce10af33..778e88bc9 100644 --- a/roles/install-docker/handlers/main.yml +++ b/roles/install-docker/handlers/main.yml @@ -1,7 +1,7 @@ --- - name: Assure docker service is running - become: yes + become: true service: name: docker enabled: yes @@ -9,7 +9,7 @@ listen: Restart docker - name: Correct group ownership on docker sock - become: yes + become: true file: path: /var/run/docker.sock group: "{{ docker_group }}" diff --git a/roles/install-docker/tasks/docker-distro.yaml b/roles/install-docker/tasks/docker-distro.yaml new file mode 100644 index 000000000..9c35c63cb --- /dev/null +++ b/roles/install-docker/tasks/docker-distro.yaml @@ -0,0 +1,14 @@ +--- + +- name: Distro block + become: true + block: + - name: Install docker + package: + name: "{{ docker_distro_packages }}" + state: present + when: + - not (use_upstream_docker | bool) + notify: Assure docker service is running + + - include_tasks: docker-setup.yaml diff --git a/roles/install-docker/tasks/docker-setup.yaml b/roles/install-docker/tasks/docker-setup.yaml new file mode 100644 index 000000000..dbc3ecc8d --- /dev/null +++ b/roles/install-docker/tasks/docker-setup.yaml @@ -0,0 +1,16 @@ +--- + +- name: Ensure "docker" group exists + group: + name: "{{ docker_group }}" + state: present + +- name: Add user to docker group + user: + name: "{{ ansible_user }}" + groups: + - "{{ docker_group }}" + append: yes + +- name: Reset ssh connection to pick up docker group + meta: reset_connection \ No newline at end of file diff --git a/roles/install-docker/tasks/docker-upstream.yaml b/roles/install-docker/tasks/docker-upstream.yaml new file mode 100644 index 000000000..4ea73bb87 --- /dev/null +++ b/roles/install-docker/tasks/docker-upstream.yaml @@ -0,0 +1,13 @@ +--- + +- name: Upstream block + become: true + block: + - name: Set up docker mirrors + include_role: + name: use-docker-mirror + + - name: Install docker-ce from upstream + include_tasks: "upstream-{{ ansible_pkg_mgr }}.yaml" + + - include_tasks: docker-setup.yaml diff --git a/roles/install-docker/tasks/main.yaml b/roles/install-docker/tasks/main.yaml index 5753f24e6..86598e7d9 100644 --- a/roles/install-docker/tasks/main.yaml +++ b/roles/install-docker/tasks/main.yaml @@ -17,10 +17,12 @@ - name: Sanity check for distro selection fail: msg: >- - This role is not known to be compatible with this distro. Check the inventory and deployment - target settings. Make sure facts are being gathered prior to executing this role. + This role is not known to be compatible with this distro and no packages have been provided + for installation. Check the inventory and deployment target settings. Make sure facts are + being gathered prior to executing this role. when: - not (docker_distro_vars_loaded | bool) + - (docker_distro_packages | length) < 1 - name: Sanity check for distro install fail: @@ -53,54 +55,11 @@ - (docker_mirror_base_url | length) < 1 - use_upstream_docker | bool -- name: Upstream block - when: - - use_upstream_docker | bool - block: - - name: Set up docker mirrors - include_role: - name: use-docker-mirror - - - name: Install docker-ce from upstream - include_tasks: "upstream-{{ ansible_pkg_mgr }}.yaml" - rescue: - - name: Notice - debug: - msg: >- - The upstream installation of docker has failed, falling back to the distro packages. - - - name: Re-Set the use upstream flag - set_fact: - use_upstream_docker: false - -- name: Install docker - become: yes - package: - name: "{{ docker_distro_packages }}" - state: present - when: - - not (use_upstream_docker | bool) - notify: Assure docker service is running - -- name: Ensure "docker" group exists - group: - name: "{{ docker_group }}" - state: present - -- name: Add user to docker group - become: yes - user: - name: "{{ ansible_user }}" - groups: - - "{{ docker_group }}" - append: yes +- include_tasks: "docker-{{ (use_upstream_docker | bool) | ternary('upstream', 'distro') }}.yaml" - name: Flush handlers before role exit meta: flush_handlers -- name: Reset ssh connection to pick up docker group - meta: reset_connection - - name: Validate ability to talk with docker command: docker ps changed_when: false diff --git a/roles/install-docker/tasks/upstream-apt.yaml b/roles/install-docker/tasks/upstream-apt.yaml index 40ad8678c..33625b576 100644 --- a/roles/install-docker/tasks/upstream-apt.yaml +++ b/roles/install-docker/tasks/upstream-apt.yaml @@ -1,17 +1,16 @@ +--- + - name: Install pre-reqs package: name: "{{ _docker_upstream_distro_required_packages }}" state: present - become: yes - name: Add docker GPG key - become: yes apt_key: data: "{{ docker_gpg_key }}" # TODO(mordred) We should add a proxy cache mirror for this - name: Add docker apt repo - become: yes template: dest: /etc/apt/sources.list.d/docker.list group: root @@ -19,10 +18,4 @@ owner: root src: sources.list.j2 -- name: Install docker - become: yes - apt: - name: "{{ docker_upstream_distro_packages }}" - state: present - update_cache: yes - notify: Restart docker +- include_tasks: upstream-package-installation.yaml diff --git a/roles/install-docker/tasks/upstream-package-installation.yaml b/roles/install-docker/tasks/upstream-package-installation.yaml new file mode 100644 index 000000000..7e83127e8 --- /dev/null +++ b/roles/install-docker/tasks/upstream-package-installation.yaml @@ -0,0 +1,8 @@ +--- + +- name: Install docker + package: + name: "{{ docker_upstream_distro_packages }}" + state: present + update_cache: yes + notify: Restart docker diff --git a/roles/install-docker/tasks/upstream-yum.yaml b/roles/install-docker/tasks/upstream-yum.yaml index 14ffd1f6e..3ffc170f1 100644 --- a/roles/install-docker/tasks/upstream-yum.yaml +++ b/roles/install-docker/tasks/upstream-yum.yaml @@ -4,7 +4,6 @@ package: name: "{{ _docker_upstream_distro_required_packages }}" state: present - become: yes - name: Create tmp gpg key file copy: @@ -18,17 +17,11 @@ # TODO(mordred) We should add a proxy cache mirror for this - name: Add docker repo - become: yes - copy: + template: dest: /etc/yum.repos.d/docker-ce.repo group: root mode: 0644 owner: root src: "{{ docker_repo_template }}" -- name: Install docker - become: yes - package: - name: "{{ docker_upstream_distro_packages }}" - state: present - notify: Restart docker +- include_tasks: upstream-package-installation.yaml diff --git a/roles/install-docker/vars/debian.yaml b/roles/install-docker/vars/debian.yaml index 111c80bb9..8ee1078bd 100644 --- a/roles/install-docker/vars/debian.yaml +++ b/roles/install-docker/vars/debian.yaml @@ -16,4 +16,4 @@ _docker_upstream_distro_packages: docker_distro_vars_loaded: true -_docker_mirror_base_url: "https://{{ docker_download_fqdn }}/linux/ubuntu" +_docker_mirror_base_url: "https://{{ docker_download_fqdn }}/linux/debian" diff --git a/roles/install-docker/vars/fedora.yaml b/roles/install-docker/vars/fedora.yaml index 31750fcc9..a77429622 100644 --- a/roles/install-docker/vars/fedora.yaml +++ b/roles/install-docker/vars/fedora.yaml @@ -11,7 +11,7 @@ _docker_upstream_distro_packages: - docker-ce-cli - containerd.io -docker_repo_template: docker-ce-centos.repo +docker_repo_template: docker-ce-centos.repo.j2 docker_distro_vars_loaded: true diff --git a/roles/install-docker/vars/opensuse.yaml b/roles/install-docker/vars/opensuse.yaml index b25ea24d4..450f939ea 100644 --- a/roles/install-docker/vars/opensuse.yaml +++ b/roles/install-docker/vars/opensuse.yaml @@ -7,4 +7,11 @@ _docker_upstream_distro_required_packages: [] _docker_upstream_distro_packages: [] +docker_repo_template: null + docker_distro_vars_loaded: true + +_docker_mirror_base_url: null + +# OpenSUSE has no upstream mirror +use_upstream_docker: false diff --git a/roles/install-docker/vars/redhat.yaml b/roles/install-docker/vars/redhat.yaml index 12536b1e9..d79659139 100644 --- a/roles/install-docker/vars/redhat.yaml +++ b/roles/install-docker/vars/redhat.yaml @@ -13,7 +13,7 @@ _docker_upstream_distro_packages: - docker-ce-cli - containerd.io -docker_repo_template: docker-ce-centos.repo +docker_repo_template: docker-ce-centos.repo.j2 docker_distro_vars_loaded: true diff --git a/roles/install-docker/vars/ubuntu.yaml b/roles/install-docker/vars/ubuntu.yaml new file mode 100644 index 000000000..111c80bb9 --- /dev/null +++ b/roles/install-docker/vars/ubuntu.yaml @@ -0,0 +1,19 @@ +--- + +_docker_distro_packages: + - docker.io + +_docker_upstream_distro_required_packages: + - apt-transport-https + - ca-certificates + - curl + - software-properties-common + +_docker_upstream_distro_packages: + - docker-ce + - docker-ce-cli + - containerd.io + +docker_distro_vars_loaded: true + +_docker_mirror_base_url: "https://{{ docker_download_fqdn }}/linux/ubuntu"