2019-01-16 13:57:02 +08:00
|
|
|
---
|
|
|
|
- name: check for python
|
|
|
|
stat:
|
2019-08-01 15:37:34 +08:00
|
|
|
path: "{{ item }}"
|
|
|
|
changed_when: false
|
|
|
|
failed_when: false
|
2019-01-16 13:57:02 +08:00
|
|
|
register: systempython
|
2019-08-01 15:37:34 +08:00
|
|
|
with_items:
|
|
|
|
- /usr/bin/python
|
|
|
|
- /usr/bin/python3
|
2019-01-16 13:57:02 +08:00
|
|
|
|
2019-08-01 15:37:34 +08:00
|
|
|
- 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
|
2019-01-16 13:57:02 +08:00
|
|
|
|
2019-08-01 15:37:34 +08:00
|
|
|
- name: check for yum package manager (RedHat/Fedora/CentOS)
|
|
|
|
raw: stat /bin/yum
|
|
|
|
changed_when: false
|
|
|
|
failed_when: false
|
|
|
|
register: stat_yum
|
2019-01-16 13:57:02 +08:00
|
|
|
|
2019-08-01 15:37:34 +08:00
|
|
|
- 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)
|