Verify python and pip command works before installing them
Update python ansible role to verify commands already works before installing new executables Change-Id: Ie16cec211059e0548f0dfa64ad34aae9ef9757e1
This commit is contained in:
parent
e9d2261951
commit
3bfacfb9d2
4
roles/python/Vagrantfile
vendored
4
roles/python/Vagrantfile
vendored
@ -5,10 +5,10 @@
|
||||
VAGRANTFILE_API_VERSION = "2"
|
||||
|
||||
# Customize the count of CPU cores on the VM
|
||||
CPUS = 4
|
||||
CPUS = 1
|
||||
|
||||
# Customize the amount of memory on the VM
|
||||
MEMORY = 8192
|
||||
MEMORY = 512
|
||||
|
||||
# Every Vagrant development environment requires a box. You can search for
|
||||
# boxes at https://vagrantcloud.com/search.
|
||||
|
@ -1,81 +1,65 @@
|
||||
---
|
||||
|
||||
- block:
|
||||
- name: check '{{ python_executable }}' is installed
|
||||
shell: |
|
||||
'{{ python_executable }}' --version 2>&1 | \
|
||||
grep 'Python {{ python_version}}'
|
||||
|
||||
- name: check '{{ python_command }}' command
|
||||
command: "'{{ python_command }}' --version"
|
||||
changed_when: false
|
||||
|
||||
- name: Discover '{{ python_command }}' executable path
|
||||
command: "which '{{ python_command }}'"
|
||||
register: discover_python_executable
|
||||
changed_when: false
|
||||
|
||||
- name: register '{{ python_command }}' executable as '{{ discover_python_executable.stdout }}'
|
||||
set_fact:
|
||||
python_executable: '{{ discover_python_executable.stdout }}'
|
||||
|
||||
rescue:
|
||||
- name: install '{{ python_name }}' build requeirements
|
||||
|
||||
- name: setup '{{ python_executable }}'
|
||||
include: setup_python.yaml
|
||||
|
||||
- name: add '{{ profile_file }}'
|
||||
become: yes
|
||||
become_user: root
|
||||
yum:
|
||||
state: present
|
||||
name: '{{ yum_install_packages }}'
|
||||
when: "(yum_install_packages | length) > 0"
|
||||
template:
|
||||
src: profile.sh.j2
|
||||
dest: '{{ profile_file }}'
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
|
||||
- name: download '{{ python_name }}' from '{{ python_url }}'
|
||||
get_url:
|
||||
url: "{{ python_url }}"
|
||||
dest: "{{ python_tar }}"
|
||||
- name: reset ssh connection to allow user changes to affect 'current login user'
|
||||
meta: reset_connection
|
||||
|
||||
- name: ensure '{{ python_src_dir | dirname }}' directory exists
|
||||
file:
|
||||
path: '{{ python_src_dir }}'
|
||||
state: directory
|
||||
|
||||
- name: extract '{{ python_tar | basename }}' into '{{ python_src_dir }}'
|
||||
unarchive:
|
||||
src: '{{ python_tar }}'
|
||||
dest: '{{ python_src_dir | dirname }}'
|
||||
remote_src: yes
|
||||
|
||||
- name: configure '{{ python_name }}'
|
||||
command:
|
||||
cmd: './configure "--prefix={{ python_prefix }}"'
|
||||
chdir: '{{ python_src_dir }}'
|
||||
|
||||
- name: compile '{{ python_name }}'
|
||||
command:
|
||||
cmd: 'make -j {{ make_jobs }}'
|
||||
chdir: '{{ python_src_dir }}'
|
||||
|
||||
- name: install '{{ python_name }}'
|
||||
become: yes
|
||||
become_user: root
|
||||
command:
|
||||
cmd: 'make install'
|
||||
chdir: '{{ python_src_dir }}'
|
||||
|
||||
- name: check '{{ python_executable }}' is installed
|
||||
shell: |
|
||||
'{{ python_executable }}' --version 2>&1 | \
|
||||
grep 'Python {{ python_version}}'
|
||||
- name: check '{{ python_command }}' command
|
||||
command: "'{{ python_command }}' --version"
|
||||
changed_when: false
|
||||
|
||||
|
||||
- block:
|
||||
- name: check '{{ pip_executable }}' is installed
|
||||
command: "'{{ pip_executable }}' --version"
|
||||
|
||||
- name: check '{{ pip_command }}' command
|
||||
command: "'{{ pip_command }}' --version"
|
||||
changed_when: false
|
||||
|
||||
- name: discover '{{ pip_command }}' executable path
|
||||
command: "which '{{ pip_command }}'"
|
||||
register: discover_pip_executable
|
||||
changed_when: false
|
||||
|
||||
- name: register '{{ pip_command }}' as '{{ discover_pip_executable.stdout }}'
|
||||
set_fact:
|
||||
pip_executable: '{{ discover_pip_executable.stdout }}'
|
||||
|
||||
rescue:
|
||||
|
||||
- name: setup '{{ pip_executable }}'
|
||||
include: setup_pip.yaml
|
||||
|
||||
- name: download Pip installer from '{{ pip_url }}'
|
||||
get_url:
|
||||
url: "{{ pip_url }}"
|
||||
dest: "{{ pip_installer }}"
|
||||
|
||||
- name: "Install '{{ pip_executable }}'"
|
||||
become: yes
|
||||
become_user: root
|
||||
command: "'{{ python_executable }}' '{{ pip_installer }}'"
|
||||
|
||||
- name: check Pip is installed for '{{ pip_executable }}'
|
||||
command: "'{{ pip_executable }}' --version"
|
||||
- name: check '{{ pip_command }}' command
|
||||
command: "'{{ pip_command }}' --version"
|
||||
changed_when: false
|
||||
|
||||
|
||||
@ -92,14 +76,3 @@
|
||||
loop:
|
||||
- "{{ pip_install_base_packages }}"
|
||||
- "{{ pip_install_packages }}"
|
||||
|
||||
|
||||
- name: add '{{ profile_file }}'
|
||||
become: yes
|
||||
become_user: root
|
||||
template:
|
||||
src: profile.sh.j2
|
||||
dest: '{{ profile_file }}'
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
|
23
roles/python/tasks/setup_pip.yaml
Normal file
23
roles/python/tasks/setup_pip.yaml
Normal file
@ -0,0 +1,23 @@
|
||||
---
|
||||
|
||||
- block:
|
||||
|
||||
- name: check '{{ pip_executable }}' is installed
|
||||
command: "'{{ pip_executable }}' --version"
|
||||
changed_when: false
|
||||
|
||||
rescue:
|
||||
|
||||
- name: download Pip installer from '{{ pip_url }}'
|
||||
get_url:
|
||||
url: "{{ pip_url }}"
|
||||
dest: "{{ pip_installer }}"
|
||||
|
||||
- name: "Install '{{ pip_executable }}'"
|
||||
become: yes
|
||||
become_user: root
|
||||
command: "'{{ python_executable }}' '{{ pip_installer }}'"
|
||||
|
||||
- name: check Pip is installed for '{{ pip_executable }}'
|
||||
command: "'{{ pip_executable }}' --version"
|
||||
changed_when: false
|
57
roles/python/tasks/setup_python.yaml
Normal file
57
roles/python/tasks/setup_python.yaml
Normal file
@ -0,0 +1,57 @@
|
||||
---
|
||||
|
||||
- block:
|
||||
- name: check '{{ python_executable }}' is installed
|
||||
shell: |
|
||||
'{{ python_executable }}' --version 2>&1 | \
|
||||
grep 'Python {{ python_version}}'
|
||||
changed_when: false
|
||||
|
||||
rescue:
|
||||
|
||||
- name: install '{{ python_name }}' build requeirements
|
||||
become: yes
|
||||
become_user: root
|
||||
yum:
|
||||
state: present
|
||||
name: '{{ yum_install_packages }}'
|
||||
when: "(yum_install_packages | length) > 0"
|
||||
|
||||
- name: download '{{ python_name }}' from '{{ python_url }}'
|
||||
get_url:
|
||||
url: "{{ python_url }}"
|
||||
dest: "{{ python_tar }}"
|
||||
|
||||
- name: ensure '{{ python_src_dir | dirname }}' directory exists
|
||||
file:
|
||||
path: '{{ python_src_dir }}'
|
||||
state: directory
|
||||
|
||||
- name: extract '{{ python_tar | basename }}' into '{{ python_src_dir }}'
|
||||
unarchive:
|
||||
src: '{{ python_tar }}'
|
||||
dest: '{{ python_src_dir | dirname }}'
|
||||
remote_src: yes
|
||||
|
||||
- name: configure '{{ python_name }}'
|
||||
command:
|
||||
cmd: './configure "--prefix={{ python_prefix }}"'
|
||||
chdir: '{{ python_src_dir }}'
|
||||
|
||||
- name: compile '{{ python_name }}'
|
||||
command:
|
||||
cmd: 'make -j {{ make_jobs }}'
|
||||
chdir: '{{ python_src_dir }}'
|
||||
|
||||
- name: install '{{ python_name }}'
|
||||
become: yes
|
||||
become_user: root
|
||||
command:
|
||||
cmd: 'make install'
|
||||
chdir: '{{ python_src_dir }}'
|
||||
|
||||
- name: check '{{ python_executable }}' is installed
|
||||
shell: |
|
||||
'{{ python_executable }}' --version 2>&1 | \
|
||||
grep 'Python {{ python_version}}'
|
||||
changed_when: false
|
@ -2,6 +2,7 @@
|
||||
|
||||
- hosts: all
|
||||
roles:
|
||||
|
||||
- role: .
|
||||
vars:
|
||||
python_version: "3.8"
|
||||
@ -11,6 +12,7 @@
|
||||
- tox
|
||||
|
||||
tasks:
|
||||
|
||||
- name: run test cases
|
||||
shell:
|
||||
cmd: tox -e py38
|
||||
@ -18,6 +20,11 @@
|
||||
register: run_test_cases
|
||||
ignore_errors: true
|
||||
|
||||
- name: Install Python devel package required to compile tox reports
|
||||
yum:
|
||||
name: python-devel
|
||||
state: latest
|
||||
|
||||
- name: produce test reports
|
||||
shell:
|
||||
cmd: tox -e report 2>&1
|
||||
|
Loading…
x
Reference in New Issue
Block a user