]> git.apps.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
refact python installation
authorGuillaume Abrioux <gabrioux@redhat.com>
Thu, 1 Aug 2019 07:37:34 +0000 (09:37 +0200)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 19 Aug 2019 18:47:14 +0000 (18:47 +0000)
This commit refacts the python installation when no available.

In order to avoid generating errors, we check for each package manager
to detect which system we are running on.

Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
(cherry picked from commit d3fa3c2d72f4956a0fa91f10b9d808107c3df3fd)

raw_install_python.yml

index f752a6096e30120c5ba766d3ea3c8315ef5dcba3..d7f3a854e8bafa582ff95af2c9265114fcd7a9e7 100644 (file)
@@ -1,27 +1,57 @@
 ---
 - name: check for python
   stat:
-    path: /usr/bin/python
-  ignore_errors: yes
+    path: "{{ item }}"
+  changed_when: false
+  failed_when: false
   register: systempython
+  with_items:
+    - /usr/bin/python
+    - /usr/bin/python3
 
-- name: install python for debian based systems
-  raw: apt-get -y install python-simplejson
-  ignore_errors: yes
-  register: result
-  when: systempython.stat is undefined or not systempython.stat.exists
-  until: result is succeeded
+- block:
+    - name: check for dnf-3 package manager (RedHat/Fedora/CentOS)
+      raw: stat /bin/dnf-3
+      changed_when: false
+      failed_when: false
+      register: stat_dnf3
 
-- name: install python for fedora
-  raw: dnf -y install python3; ln -sf /usr/bin/python3 /usr/bin/python creates=/usr/bin/python
-  ignore_errors: yes
-  register: result
-  when: systempython.stat is undefined or not systempython.stat.exists
-  until: (result is succeeded) and ('Failed' not in result.stdout)
+    - name: check for yum package manager (RedHat/Fedora/CentOS)
+      raw: stat /bin/yum
+      changed_when: false
+      failed_when: false
+      register: stat_yum
 
-- name: install python for opensuse
-  raw: zypper -n install python-base creates=/usr/bin/python2.7
-  ignore_errors: yes
-  register: result
-  when: systempython.stat is undefined or not systempython.stat.exists
-  until: result is succeeded
+    - name: check for apt package manager (Debian/Ubuntu)
+      raw: stat /usr/bin/apt-get
+      changed_when: false
+      failed_when: false
+      register: stat_apt
+
+    - name: check for zypper package manager (OpenSUSE)
+      raw: stat /usr/bin/zypper
+      changed_when: false
+      failed_when: false
+      register: stat_zypper
+
+    - name: install python for RedHat based OS - dnf
+      raw: >
+        {{ 'dnf' if stat_dnf3.rc == 0 else 'yum' }} -y install python3;
+        ln -sf /usr/bin/python3 /usr/bin/python
+        creates=/usr/bin/python
+      register: result
+      until: (result is succeeded) and ('Failed' not in result.stdout)
+      when: stat_dnf3.rc == 0 or stat_yum.rc == 0
+
+    - name: install python for debian based OS
+      raw: apt-get -y install python-simplejson
+      register: result
+      until: result is succeeded
+      when: stat_apt.rc == 0
+
+    - name: install python for opensuse
+      raw: zypper -n install python-base
+      register: result
+      until: result is succeeded
+      when: stat_zypper.rc == 0
+  when: not True in (systempython.results | selectattr('stat', 'defined') | map(attribute='stat.exists') | list | unique)
\ No newline at end of file