Browse Source

Allow pypiserver to be upgraded before repo build

To cater for a situation where the pypiserver package is changing,
but the repo does not yet have the package built, we need to ensure
that the install task for it can fetch from pypi (or the designated
pypi mirror). To do this we try the local repo first, then fall back
to using the designated default index which defaults to pypi.

Change-Id: I1a2d36793fccc4c50f00247c8d19501ad8816517
Jesse Pretorius 1 year ago
parent
commit
4e3213f4c6
1 changed files with 40 additions and 15 deletions
  1. 40
    15
      tasks/repo_install.yml

+ 40
- 15
tasks/repo_install.yml View File

@@ -55,19 +55,44 @@
55 55
   retries: 5
56 56
   delay: 2
57 57
 
58
-- name: Install pip packages
59
-  pip:
60
-    name: "{{ repo_pypiserver_pip_packages }}"
61
-    state: "{{ repo_server_pip_package_state }}"
62
-    virtualenv: "{{ repo_pypiserver_bin | dirname }}"
63
-    virtualenv_site_packages: "no"
64
-    extra_args: >-
65
-      {{ (pip_install_upper_constraints is defined) | ternary('--constraint ' + pip_install_upper_constraints | default(''),'') }}
66
-      {{ pip_install_options | default('') }}
67
-  register: install_packages
68
-  until: install_packages | success
69
-  retries: 5
70
-  delay: 2
71
-  notify:
72
-    - reload pypiserver
58
+# Note(odyssey4me):
59
+# To cater for a situation where the pip packages are changing, but the repo
60
+# does not yet have the package built, we need to ensure that this task can
61
+# fetch from pypi. To do this we try the local repo first, then fall back to
62
+# using pypi.
63
+- name: Try installing from the repo first, then fall back to using pypi
64
+  block:
65
+    - name: Install pip packages (from repo)
66
+      pip:
67
+        name: "{{ repo_pypiserver_pip_packages }}"
68
+        state: "{{ repo_server_pip_package_state }}"
69
+        virtualenv: "{{ repo_pypiserver_bin | dirname }}"
70
+        virtualenv_site_packages: "no"
71
+        extra_args: >-
72
+          {{ (pip_install_upper_constraints is defined) | ternary('--constraint ' + pip_install_upper_constraints | default(''),'') }}
73
+          {{ pip_install_options | default('') }}
74
+      register: install_packages
75
+      until: install_packages | success
76
+      retries: 5
77
+      delay: 2
78
+      notify:
79
+        - reload pypiserver
80
+  rescue:
81
+    - name: Install pip packages (from pypi mirror)
82
+      pip:
83
+        name: "{{ repo_pypiserver_pip_packages }}"
84
+        state: "{{ repo_server_pip_package_state }}"
85
+        virtualenv: "{{ repo_pypiserver_bin | dirname }}"
86
+        virtualenv_site_packages: "no"
87
+        extra_args: >-
88
+          --index-url {{ repo_build_pip_default_index | default('https://pypi.python.org/simple') }}
89
+          --trusted-host {{ (repo_build_pip_default_index | default('https://pypi.python.org/simple')) | netloc_no_port }}
90
+          {{ (pip_install_upper_constraints is defined) | ternary('--constraint ' + pip_install_upper_constraints | default(''),'') }}
91
+          {{ pip_install_options | default('') }}
92
+      register: install_packages
93
+      until: install_packages | success
94
+      retries: 5
95
+      delay: 2
96
+      notify:
97
+        - reload pypiserver
73 98
 

Loading…
Cancel
Save