From 4b2d13995d738295e545314f62560d10647f32a8 Mon Sep 17 00:00:00 2001 From: Guillaume Abrioux Date: Thu, 1 Aug 2019 09:37:34 +0200 Subject: [PATCH] refact python installation 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 (cherry picked from commit d3fa3c2d72f4956a0fa91f10b9d808107c3df3fd) --- raw_install_python.yml | 70 ++++++++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 20 deletions(-) diff --git a/raw_install_python.yml b/raw_install_python.yml index f752a6096..d7f3a854e 100644 --- a/raw_install_python.yml +++ b/raw_install_python.yml @@ -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