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-09-11 23:44:30 +08:00
|
|
|
- /usr/libexec/platform-python
|
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
|
2019-08-20 19:32:32 +08:00
|
|
|
when: not True in (systempython.results | selectattr('stat', 'defined') | map(attribute='stat.exists') | list | unique)
|
|
|
|
|
|
|
|
- name: install python-xml for opensuse only if python2 is installed already
|
|
|
|
raw: zypper -n install python-xml
|
|
|
|
register: result
|
|
|
|
until: result is succeeded
|
|
|
|
with_items: "{{ systempython.results }}"
|
|
|
|
when:
|
|
|
|
- stat_zypper.rc is defined
|
|
|
|
- stat_zypper.rc == 0
|
|
|
|
- item.stat.exists | bool
|
|
|
|
- item.stat.path == '/usr/bin/python'
|