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