From bd9c9cd617cbaef51f3e2206922c0391739bba63 Mon Sep 17 00:00:00 2001 From: Logan V Date: Sun, 12 Jun 2016 15:16:39 -0500 Subject: [PATCH] Refactor pip_install to support offline deployment Optionally support the download and installation of pip and its dependencies via the deployment host to remove the dependence of internet connectivity on remote containers. When pip_offline_install is true, download get-pip.py and the pip installation wheels to the deployment host. These wheels along with get-pip.py are copied to the remote container and the installation is performed offline. Change-Id: Ic6583c54976b6fb083d9c67d055897c15bce05dc --- defaults/main.yml | 6 + .../notes/install-local-019edab04ffc8347.yaml | 8 ++ tasks/install_offline.yml | 122 ++++++++++++++++++ tasks/{install.yml => install_online.yml} | 0 tasks/main.yml | 8 +- 5 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/install-local-019edab04ffc8347.yaml create mode 100644 tasks/install_offline.yml rename tasks/{install.yml => install_online.yml} (100%) diff --git a/defaults/main.yml b/defaults/main.yml index a34462a..ba7d52d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -17,6 +17,12 @@ pip_upstream_url: https://bootstrap.pypa.io/get-pip.py pip_fallback_url: https://raw.githubusercontent.com/pypa/get-pip/master/get-pip.py +# Allow the deployer to force pip to download locally to the deployment host +# and copy it to the remote container for installation. Useful for environments +# where the containers lack internet access. +pip_offline_install: false +pip_packages_tmp: /tmp/pip_install + # Additional options that you might want to pass to "get-pip.py" when installing pip. # Default `pip_get_pip_options` is an empty string. pip_get_pip_options: "" diff --git a/releasenotes/notes/install-local-019edab04ffc8347.yaml b/releasenotes/notes/install-local-019edab04ffc8347.yaml new file mode 100644 index 0000000..614be99 --- /dev/null +++ b/releasenotes/notes/install-local-019edab04ffc8347.yaml @@ -0,0 +1,8 @@ +--- +features: + - pip can be installed via the deployment host using the + new variable ``pip_offline_install``. This can be useful + in environments where the containers lack internet + connectivity. Please refer to the `limited connectivity installation guide + `_ + for more information. diff --git a/tasks/install_offline.yml b/tasks/install_offline.yml new file mode 100644 index 0000000..ce4f5cb --- /dev/null +++ b/tasks/install_offline.yml @@ -0,0 +1,122 @@ +--- +# Copyright 2016, Logan Vig +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: Get Modern PIP to local + local_action: + module: get_url + url: "{{ pip_upstream_url }}" + dest: "/tmp/get-pip.py" + force: "yes" + validate_certs: "{{ pip_validate_certs }}" + register: get_pip_local + until: get_pip_local | success + ignore_errors: True + retries: 5 + delay: 2 + run_once: yes + tags: + - pip-install-local + - pip-install-script + +- name: Get Modern PIP using fallback URL to local + local_action: + module: get_url + url: "{{ pip_fallback_url }}" + dest: "/tmp/get-pip.py" + force: "yes" + validate_certs: "{{ pip_validate_certs }}" + when: get_pip_local | failed + register: get_pip_local_fallback + until: get_pip_local_fallback | success + retries: 5 + delay: 2 + run_once: yes + tags: + - pip-install-local + - pip-install-script + + +- name: Create local pip package cache + local_action: + module: file + path: "{{ pip_packages_tmp }}" + state: directory + run_once: yes + tags: + - pip-install-local + +- name: pip cache install files locally + local_action: shell python /tmp/get-pip.py -d '{{ pip_packages_tmp | quote }}' {{ pip_get_pip_options }} {{ pip_packages | map('quote') | join (' ') }} + register: pip_local_cache + until: pip_local_cache | success + retries: 3 + delay: 2 + +- name: Distribute the modern PIP installer + copy: + src: "/tmp/get-pip.py" + dest: "/opt/get-pip.py" + tags: + - pip-install-local + - pip-install-script + +- name: Distribute PIP install files + copy: + src: "{{ pip_packages_tmp }}/" + dest: "{{ pip_packages_tmp }}" + tags: + - pip-install-cache-distribute + - pip-install + +- name: Install PIP + shell: "python /opt/get-pip.py --no-index --find-links={{ pip_packages_tmp | quote }} {{ pip_get_pip_options }} {{ pip_packages | map('quote') | join (' ') }}" + ignore_errors: true + register: pip_install + until: pip_install | success + retries: 3 + delay: 2 + +- name: Install PIP (fall back mode) + shell: "python /opt/get-pip.py --isolated --no-index --find-links={{ pip_packages_tmp | quote }} {{ pip_get_pip_options }} {{ pip_packages | map('quote') | join (' ') }}" + when: pip_install.rc != 0 + register: pip_install_fall_back + until: pip_install_fall_back | success + retries: 3 + delay: 2 + +- name: Clean up local get-pip.py + local_action: + module: file + path: "/tmp/get-pip.py" + state: absent + run_once: yes + tags: + - pip-install-cleanup + +- name: Clean up local install cache + local_action: + module: file + path: "{{ pip_packages_tmp }}" + state: absent + run_once: yes + tags: + - pip-install-cleanup + +- name: Clean up remote install files + file: + path: "{{ pip_packages_tmp }}" + state: absent + tags: + - pip-install-cleanup diff --git a/tasks/install.yml b/tasks/install_online.yml similarity index 100% rename from tasks/install.yml rename to tasks/install_online.yml diff --git a/tasks/main.yml b/tasks/main.yml index 1af8539..2504057 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -21,6 +21,12 @@ when: - pip_lock_to_internal_repo | bool -- include: install.yml +- include: install_online.yml + when: not pip_offline_install | bool + tags: + - pip-install + +- include: install_offline.yml + when: pip_offline_install | bool tags: - pip-install