tobiko/roles/python/tasks/main.yaml

106 lines
2.7 KiB
YAML

---
- 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
- 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
- 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 }}"
- name: add '{{ profile_file }}'
become: yes
become_user: root
template:
src: profile.sh.j2
dest: '{{ profile_file }}'
owner: root
group: root
mode: '0644'