Skip to content

Commit ae14a8b

Browse files
committed
Push installation conditional into OS task list for better handling and pip installation
Signed-off-by: Webster Mudge <[email protected]>
1 parent c30f31d commit ae14a8b

File tree

3 files changed

+144
-184
lines changed

3 files changed

+144
-184
lines changed

roles/prereq_python/tasks/RedHat.yml

Lines changed: 30 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,69 +13,43 @@
1313
# limitations under the License.
1414

1515
---
16-
# Python3 and Pip
17-
- name: Install supported version of Python3
16+
17+
- name: Install supported Python
1818
when:
19-
# (
20-
# python_version is defined and
21-
# python_version |
22-
# ansible.builtin.split(".") |
23-
# first == "3"
24-
# ) or (
25-
prereq_python_supported |
26-
first |
27-
ansible.builtin.split(".") |
28-
first == "3"
29-
# )
19+
prereq_python_upgrade and
20+
prereq_python_supported is not contains(
21+
[
22+
ansible_python["version"]["major"],
23+
ansible_python["version"]["minor"]
24+
] |
25+
join(".")
26+
)
3027
vars:
31-
__p3_version: "{{ prereq_python_supported | first | string }}"
28+
__python_version: "{{ prereq_python_supported | first | string }}"
3229
block:
33-
- name: Install python3
34-
ansible.builtin.package:
35-
name: "{{ python3_package | default('python' + __p3_version) }}"
36-
state: present
37-
38-
# - name: Download and install
39-
# when: python3_package is not defined
40-
# ansible.builtin.debug:
41-
# msg:
42-
# - "TODO - install Python version {{ __required_python_version }}"
43-
44-
- name: Install pip3
30+
- name: Install supported version of Python3
31+
when:
32+
prereq_python_supported |
33+
first |
34+
ansible.builtin.split(".") |
35+
first == "3"
4536
ansible.builtin.package:
46-
name: "{{ python3_pip_package | default('python' + __p3_version + '-pip') }}"
37+
name: "{{ python_packages | default('python' + __python_version) }}"
4738
state: present
4839

49-
# Python2 and Pip
50-
- name: Ensure supported version of Python2
51-
when:
52-
# (
53-
# python_version is defined and
54-
# python_version |
55-
# ansible.builtin.split(".") |
56-
# first == "2"
57-
# ) or (
58-
prereq_python_supported |
59-
first |
60-
ansible.builtin.split(".") |
61-
first == "2"
62-
# )
63-
vars:
64-
__p2_version: "{{ prereq_python_supported | first | string }}"
65-
block:
6640
# TODO Confirm Python2 package names
67-
- name: Install python2
41+
- name: Install supported version of Python2
42+
when:
43+
prereq_python_supported |
44+
first |
45+
ansible.builtin.split(".") |
46+
first == "2"
6847
ansible.builtin.package:
69-
name: "{{ python2_package | default('python' + __p2_version) }}"
48+
name: "{{ python_packages | default('python' + __python_version) }}"
7049
state: present
7150

72-
# - name: Download and install
73-
# when: python2_package is not defined
74-
# ansible.builtin.debug:
75-
# msg:
76-
# - "TODO - install Python version {{ __required_python_version }}"
77-
78-
- name: Install pip2
79-
ansible.builtin.package:
80-
name: "{{ python2_pip_package | default('python' + __p2_version + '-pip') }}"
81-
state: present
51+
# TODO Confirm Python2-pip package names
52+
- name: Install pip
53+
ansible.builtin.package:
54+
name: "{{ python_pip_packages | default('python-pip') }}"
55+
state: present

roles/prereq_python/tasks/Ubuntu.yml

Lines changed: 106 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -13,120 +13,123 @@
1313
# limitations under the License.
1414

1515
---
16-
# Python3 and Pip
17-
- name: Install supported version of Python3
16+
17+
- name: Install supported Python
1818
when:
19-
# (
20-
# python_version is defined and
21-
# python_version |
22-
# ansible.builtin.split(".") |
23-
# first == "3"
24-
# ) or (
25-
prereq_python_supported |
26-
first |
27-
ansible.builtin.split(".") |
28-
first == "3"
29-
# )
19+
prereq_python_upgrade and
20+
prereq_python_supported is not contains(
21+
[
22+
ansible_python["version"]["major"],
23+
ansible_python["version"]["minor"]
24+
] |
25+
join(".")
26+
)
3027
vars:
31-
__p3_version: "{{ prereq_python_supported | first | string }}"
28+
__python_version: "{{ prereq_python_supported | first | string }}"
3229
block:
33-
- name: Ensure required dependencies are installed
34-
ansible.builtin.package:
35-
name:
36-
- build-essential
37-
- zlib1g-dev
38-
- libncurses5-dev
39-
- libgdbm-dev
40-
- libnss3-dev
41-
- libssl-dev
42-
- libreadline-dev
43-
- libffi-dev
44-
- curl
45-
- libsqlite3-dev
46-
- libbz2-dev
47-
state: present
48-
update_cache: true
49-
50-
- name: Extract Python3 source
51-
ansible.builtin.unarchive:
52-
src: https://www.python.org/ftp/python/{{ __p3_version }}/Python-{{ __p3_version }}.tgz
53-
dest: /tmp
54-
remote_src: true
30+
- name: Install supported version of Python3
31+
when:
32+
prereq_python_supported |
33+
first |
34+
ansible.builtin.split(".") |
35+
first == "3"
36+
block:
37+
- name: Install Python3 package
38+
when: python_packages is defined
39+
ansible.builtin.package:
40+
name: "{{ python_packages }}"
41+
state: present
5542

56-
- name: Configure Python3 for installation
57-
ansible.builtin.command: ./configure --enable-optimizations
58-
args:
59-
chdir: /tmp/Python-{{ __p3_version }}
60-
changed_when: true
43+
- name: Install Python3 from source
44+
when: python_packages is not defined
45+
block:
46+
- name: Ensure required dependencies are installed
47+
ansible.builtin.package:
48+
name:
49+
- build-essential
50+
- zlib1g-dev
51+
- libncurses5-dev
52+
- libgdbm-dev
53+
- libnss3-dev
54+
- libssl-dev
55+
- libreadline-dev
56+
- libffi-dev
57+
- curl
58+
- libsqlite3-dev
59+
- libbz2-dev
60+
state: present
61+
update_cache: true
6162

62-
- name: Build Python3 'all' target with extra arguments
63-
community.general.make:
64-
chdir: /tmp/Python-{{ __p3_version }}
65-
target: altinstall
63+
- name: Extract Python3 source
64+
ansible.builtin.unarchive:
65+
src: https://www.python.org/ftp/python/{{ __python_version }}/Python-{{ __python_version }}.tgz
66+
dest: /tmp
67+
remote_src: true
6668

67-
- name: Ensure pip is installed
68-
ansible.builtin.package:
69-
name: python3-pip
70-
state: present
69+
- name: Configure Python3 for installation
70+
ansible.builtin.command: ./configure --enable-optimizations
71+
args:
72+
chdir: /tmp/Python-{{ __python_version }}
73+
changed_when: true
7174

72-
# Python2 and Pip
73-
- name: Ensure supported version of Python2
74-
when:
75-
# (
76-
# python_version is defined and
77-
# python_version |
78-
# ansible.builtin.split(".") |
79-
# first == "2"
80-
# ) or (
81-
prereq_python_supported |
82-
first |
83-
ansible.builtin.split(".") |
84-
first == "2"
85-
# )
86-
vars:
87-
__p2_version: "{{ prereq_python_supported | first | string }}"
88-
block:
89-
# Install Python2 via system package
90-
- name: Install Python2 package
91-
when: python2_package_install
92-
ansible.builtin.package:
93-
name: "python{{ __p2_version }}"
94-
state: present
75+
- name: Build Python3 'all' target with extra arguments
76+
community.general.make:
77+
chdir: /tmp/Python-{{ __python_version }}
78+
target: altinstall
9579

96-
# Install Python2 via source
97-
- name: Install Python2 source
98-
when: not python2_package_install
80+
- name: Install supported version of Python2
81+
when:
82+
prereq_python_supported |
83+
first |
84+
ansible.builtin.split(".") |
85+
first == "2"
9986
block:
100-
- name: Ensure required dependencies are installed
87+
# Most likely need to update this to use get-pip.py and the like
88+
- name: Install Python2 package
89+
when: python_packages is defined
10190
ansible.builtin.package:
102-
name:
103-
- build-essential
104-
- zlib1g-dev
105-
- libncurses5-dev
106-
- libgdbm-dev
107-
- libnss3-dev
108-
- libssl-dev
109-
- libreadline-dev
110-
- libffi-dev
111-
- curl
112-
- libsqlite3-dev
113-
- libbz2-dev
91+
name: "{{ python_packages }}"
11492
state: present
115-
update_cache: true
11693

117-
- name: Extract Python2 source
118-
ansible.builtin.unarchive:
119-
src: https://www.python.org/ftp/python/{{ __p2_version }}/Python-{{ __p2_version }}.tgz
120-
dest: /tmp
121-
remote_src: true
94+
- name: Install Python2 from source
95+
when: python_packages is not defined
96+
block:
97+
- name: Ensure required dependencies are installed
98+
ansible.builtin.package:
99+
name:
100+
- build-essential
101+
- zlib1g-dev
102+
- libncurses5-dev
103+
- libgdbm-dev
104+
- libnss3-dev
105+
- libssl-dev
106+
- libreadline-dev
107+
- libffi-dev
108+
- curl
109+
- libsqlite3-dev
110+
- libbz2-dev
111+
state: present
112+
update_cache: true
113+
114+
- name: Extract Python2 source
115+
ansible.builtin.unarchive:
116+
src: https://www.python.org/ftp/python/{{ __python_version }}/Python-{{ __python_version }}.tgz
117+
dest: /tmp
118+
remote_src: true
119+
120+
- name: Configure Python2 for installation
121+
ansible.builtin.command: ./configure --enable-optimizations
122+
args:
123+
chdir: /tmp/Python-{{ __python_version }}
124+
changed_when: true
122125

123-
- name: Configure Python2 for installation
124-
ansible.builtin.command: ./configure --enable-optimizations
125-
args:
126-
chdir: /tmp/Python-{{ __p2_version }}
127-
changed_when: true
126+
- name: Build Python2 'all' target with extra arguments
127+
community.general.make:
128+
chdir: /tmp/Python-{{ __python_version }}
129+
target: altinstall
128130

129-
- name: Build Python2 'all' target with extra arguments
130-
community.general.make:
131-
chdir: /tmp/Python-{{ __p2_version }}
132-
target: altinstall
131+
# TODO Confirm Python2-pip package names
132+
- name: Ensure pip is installed
133+
ansible.builtin.package:
134+
name: "{{ python_pip_packages | default('python3-pip') }}"
135+
state: present

roles/prereq_python/tasks/main.yml

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,16 @@
3939
}}"
4040
supported_os: "{{ prereq_python_supported_os_map[ansible_facts['distribution']] | default(ansible_facts['distribution']) }}"
4141

42-
# - name: Validate specified Python against supported versions
43-
# when: python_version is defined
44-
# ansible.builtin.assert:
45-
# that:
46-
# - prereq_python_supported is contains(python_split[:2] | join("."))
47-
# failed_msg:
48-
# "Python version {{ python_version }} is not supported for Cloudera Manager
49-
# {{ cloudera_manager_version }} and/or Cloudera Runtime {{ cloudera_runtime_version }}"
50-
# vars:
51-
# python_version_split: "{{ python_version | ansible.builtin.split('.') }}"
42+
- name: Confirm Python version(s) for Cloudera Runtime and Manager versions and OS
43+
ansible.builtin.assert:
44+
that:
45+
- prereq_python_supported | length > 0
46+
fail_msg:
47+
"{{ ansible_facts['distribution'] }} {{ ansible_facts['distribution_version'] }}
48+
is not supported by Cloudera Manager {{ cloudera_manager_version }}
49+
and Cloudera Runtime {{ cloudera_runtime_version }}"
5250

5351
- name: Update or install Python
54-
when:
55-
56-
# (
57-
# python_version is defined and
58-
# python_version is not version(ansible_python_version, "eq", version_type="pep440")
59-
# ) or (
60-
prereq_python_upgrade and
61-
prereq_python_supported is not contains(
62-
[
63-
ansible_python["version"]["major"],
64-
ansible_python["version"]["minor"]
65-
] |
66-
join(".")
67-
)
68-
# )
6952
ansible.builtin.include_tasks: "{{ item }}"
7053
with_first_found:
7154
- "{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_version'] }}.yml"

0 commit comments

Comments
 (0)