Commit 93d8e57d authored by Chris's avatar Chris
Browse files

Update bootstrap tasks to ensure Python is installed

This change forces the bootstrap tasks to fail if an executable Python
interpreter can not be found. It also doesn't install Python if it can't find an
executable interpreter anymore.
parent efc005b9
......@@ -15,5 +15,12 @@ common_utils:
- screen
- unzip
- vim
# The path to the python executable to use
# If set and the path is executable, then it will be used.
# Else if Python 2 is executable, use it.
# Else if Python 3 is executable, use if.
# Else, fail.
ansible_python_interpreter:
...
# vi: set ts=2 sts=2 sw=2 et ft=yaml:
---
- block:
- name: Check if Python is installed
raw: test -x /usr/bin/python
- name: Boostrap the host by selecting which Python interpreter to use, and other OS specific stuff
tags: bootstrap
block:
# If ansible_python_interpreter is set and exists, use it.
# Elif python 2 exists, use it.
# Elif python 3 exists, use it.
# Else, fail.
- name: Figure out which version of Python to use
when: ansible_python_interpreter is not defined or not ansible_python_interpreter
block:
- name: Check if /usr/bin/python is executable
raw: 'test -x /usr/bin/python'
changed_when: false
failed_when: false
register: python_default
- name: Set 'ansible_python_interpreter' to /usr/bin/python
when: python_default.rc is defined and python_default.rc == 0
set_fact:
ansible_python_interpreter: /usr/bin/python
- name: Check if /usr/bin/python2 is executable
raw: 'test -x /usr/bin/python2'
changed_when: false
failed_when: false
register: python_2
- name: Set 'ansible_python_interpreter' to /usr/bin/python2
when: python_2.rc is defined and python_2.rc == 0
set_fact:
ansible_python_interpreter: /usr/bin/python2
- name: Check if /usr/bin/python3 is executable
raw: 'test -x /usr/bin/python3'
changed_when: false
failed_when: false
register: python_3
- name: Set 'ansible_python_interpreter' to /usr/bin/python3
when: python_3.rc is defined and python_3.rc == 0
set_fact:
ansible_python_interpreter: /usr/bin/python3
# - debug:
# var: ansible_python_interpreter
- name: Check if 'ansible_python_interpreter' is executable
raw: 'test -x {{ ansible_python_interpreter }}'
changed_when: false
failed_when: false
register: result
register: python_executable
- name: Assert that 'ansible_python_interpreter' is executable
assert:
that:
- ansible_python_interpreter is defined and ansible_python_interpreter
- python_executable.rc is defined and python_executable.rc == 0
- name: Install Python
raw: >
(test -e /etc/redhat-release && yum install -y python)
|| (test -e /etc/debian_version && apt-get -y update && apt-get install -y python)
when: result.rc == 1
# - name: Install Python
# raw: >
# (test -e /etc/redhat-release && yum install -y python)
# || (test -e /etc/debian_version && apt-get -y update && apt-get install -y python)
# when: result.rc is defined and result.rc == 1
- name: Gather facts to determine host OS
setup:
......@@ -34,6 +81,5 @@
- tasks/bootstrap_{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml
- tasks/bootstrap_{{ ansible_distribution | lower }}.yml
- tasks/bootstrap_{{ ansible_os_family | lower }}.yml
tags: bootstrap
...
# vi: set ts=2 sts=2 sw=2 et ft=yaml:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment