Use /usr/local as default python prefix
* Restructure the role to move logic out of main tasks file. * Use /usr/local as default prefix for python commands as expected by DevStack * Use 4 cores in Vagrant to compile python faster Change-Id: I87024f4397649000d168a444ba091fef9671f8bd
This commit is contained in:
parent
76dd641cc5
commit
72b57b7adf
|
@ -5,7 +5,7 @@
|
|||
VAGRANTFILE_API_VERSION = "2"
|
||||
|
||||
# Customize the count of CPU cores on the VM
|
||||
CPUS = 1
|
||||
CPUS = 4
|
||||
|
||||
# Customize the amount of memory on the VM
|
||||
MEMORY = 512
|
||||
|
|
|
@ -2,18 +2,20 @@ python_release: "3.8.0"
|
|||
python_version: "3.8"
|
||||
python_command: "python{{ python_version }}"
|
||||
python_name: "Python-{{ python_release }}"
|
||||
python_prefix: "/opt/{{ python_name }}"
|
||||
python_prefix: "/usr/local"
|
||||
python_executable: "{{ python_prefix }}/bin/{{ python_command }}"
|
||||
python_url: "https://www.python.org/ftp/python/{{ python_release }}/{{ python_name }}.tgz"
|
||||
python_tar: "{{ ansible_env.HOME }}/{{ python_url | basename }}"
|
||||
python_src_dir: "{{ ansible_env.HOME }}/{{ python_name }}"
|
||||
python_configure_flags: "" # ""--enable-optimizations"
|
||||
python_profile_file: "/etc/profile.d/{{ python_name }}.sh"
|
||||
python_sudoers_file: "/etc/sudoers.d/60_{{python_name}}"
|
||||
|
||||
pip_command: "pip{{ python_version }}"
|
||||
pip_executable: "{{ python_prefix }}/bin/{{ pip_command }}"
|
||||
pip_url: "https://bootstrap.pypa.io/get-pip.py"
|
||||
pip_installer: "{{ ansible_env.HOME }}/{{ pip_url | basename }}"
|
||||
|
||||
profile_file: "/etc/profile.d/{{ python_name }}.sh"
|
||||
make_jobs: "{{ ansible_processor_vcpus }}"
|
||||
|
||||
yum_install_packages:
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
|
||||
- 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 }}' executable as '{{ discover_pip_executable.stdout }}'
|
||||
set_fact:
|
||||
pip_executable: '{{ discover_pip_executable.stdout }}'
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
|
||||
- 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 }}'
|
|
@ -1,107 +1,30 @@
|
|||
---
|
||||
|
||||
- block:
|
||||
|
||||
- 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 }}'
|
||||
- include: check_python.yaml
|
||||
|
||||
rescue:
|
||||
- include: setup_python.yaml
|
||||
- include: check_python.yaml
|
||||
|
||||
- name: setup '{{ python_executable }}'
|
||||
include: setup_python.yaml
|
||||
|
||||
- name: add '{{ profile_file }}'
|
||||
become: yes
|
||||
become_user: root
|
||||
template:
|
||||
src: profile.sh.j2
|
||||
dest: '{{ profile_file }}'
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
|
||||
- name: reset ssh connection to allow user changes to affect 'current login user'
|
||||
meta: reset_connection
|
||||
|
||||
- name: check '{{ python_command }}' command
|
||||
command: "'{{ python_command }}' --version"
|
||||
changed_when: false
|
||||
- block:
|
||||
- include: check_pip.yaml
|
||||
rescue:
|
||||
- include: setup_pip.yaml
|
||||
- include: check_pip.yaml
|
||||
|
||||
|
||||
- become: yes
|
||||
become_user: root
|
||||
block:
|
||||
|
||||
- name: check sudo '{{ python_command }}' command
|
||||
command: "'{{ python_command }}' --version"
|
||||
changed_when: false
|
||||
- include: check_python.yaml
|
||||
- include: check_pip.yaml
|
||||
|
||||
rescue:
|
||||
|
||||
- name: get sudo 'secure_path'
|
||||
shell: |
|
||||
cat /etc/sudoers |
|
||||
awk '($1 == "Defaults" && $2 == "secure_path"){print $NF}'
|
||||
changed_when: false
|
||||
register: get_sudo_secure_path
|
||||
|
||||
- name: add '{{ python_executable | dirname }}' to sudo 'secure_path'
|
||||
lineinfile:
|
||||
regex: '{{ get_sudo_secure_path.stdout }}'
|
||||
path: /etc/sudoers
|
||||
line: 'Defaults secure_path = {{ python_executable | dirname }}:{{ get_sudo_secure_path.stdout }}'
|
||||
validate: '/usr/sbin/visudo -cf %s'
|
||||
|
||||
- name: check '{{ python_command }}' command
|
||||
command: "'{{ python_command }}' --version"
|
||||
changed_when: false
|
||||
- include: setup_sudo.yaml
|
||||
- include: check_python.yaml
|
||||
- include: check_pip.yaml
|
||||
|
||||
|
||||
- block:
|
||||
|
||||
- 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: check '{{ pip_command }}' command
|
||||
command: "'{{ pip_command }}' --version"
|
||||
changed_when: false
|
||||
|
||||
|
||||
- name: "ensure base Python packages are installed and up-to-date"
|
||||
become: true
|
||||
become_user: root
|
||||
pip:
|
||||
executable: '{{ pip_executable }}'
|
||||
state: latest
|
||||
name: "{{ item }}"
|
||||
vars:
|
||||
ansible_python_interpreter: '{{ python_executable }}'
|
||||
when: (item | length ) > 0
|
||||
loop:
|
||||
- "{{ pip_install_base_packages }}"
|
||||
- "{{ pip_install_packages }}"
|
||||
- include: update_packages.yaml
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
---
|
||||
|
||||
- block:
|
||||
|
||||
- name: check '{{ python_executable }}' is installed
|
||||
shell: |
|
||||
'{{ python_executable }}' --version 2>&1 | \
|
||||
|
@ -35,8 +36,9 @@
|
|||
|
||||
- name: configure '{{ python_name }}'
|
||||
command:
|
||||
cmd: './configure "--prefix={{ python_prefix }}"'
|
||||
chdir: '{{ python_src_dir }}'
|
||||
cmd: |
|
||||
./configure '--prefix={{ python_prefix }}' {{ python_configure_flags }}
|
||||
|
||||
- name: compile '{{ python_name }}'
|
||||
command:
|
||||
|
@ -55,3 +57,21 @@
|
|||
'{{ python_executable }}' --version 2>&1 | \
|
||||
grep 'Python {{ python_version}}'
|
||||
changed_when: false
|
||||
|
||||
|
||||
- name: add '{{ python_profile_file }}'
|
||||
become: yes
|
||||
become_user: root
|
||||
template:
|
||||
src: profile.sh.j2
|
||||
dest: '{{ python_profile_file }}'
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
|
||||
- name: reset ssh connection to allow environment variable changes
|
||||
meta: reset_connection
|
||||
|
||||
- name: check '{{ python_command }}' command
|
||||
command: "'{{ python_command }}' --version"
|
||||
changed_when: false
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
|
||||
- name: discover sudo secure_path
|
||||
command: |
|
||||
awk '($1 == "Defaults" && $2 == "secure_path"){print $NF}' /etc/sudoers
|
||||
register: discover_sudo_secure_path
|
||||
|
||||
|
||||
- name: add '{{ python_executable | dirname }}' to sudo 'secure_path'
|
||||
lineinfile:
|
||||
regex: '{{ discover_sudo_secure_path.stdout }}$'
|
||||
path: /etc/sudoers
|
||||
line:
|
||||
'Defaults secure_path = {{ python_executable | dirname }}:{{ discover_sudo_secure_path.stdout }}'
|
||||
validate: '/usr/sbin/visudo -cf %s'
|
||||
when:
|
||||
- (python_executable | dirname) not in discover_sudo_secure_path.stdout
|
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
|
||||
- name: "ensure required Python packages are installed and up-to-date"
|
||||
become: true
|
||||
become_user: root
|
||||
pip:
|
||||
name: "{{ item }}"
|
||||
executable: '{{ pip_executable }}'
|
||||
state: latest
|
||||
vars:
|
||||
ansible_python_interpreter: '{{ python_executable }}'
|
||||
when: (item | length ) > 0
|
||||
loop:
|
||||
- "{{ pip_install_base_packages }}"
|
||||
- "{{ pip_install_packages }}"
|
|
@ -0,0 +1 @@
|
|||
Defaults secure_path = {{ secure_path }}
|
Loading…
Reference in New Issue