From 93d8e57d291a10e385032b4303ca11c4a133afbe Mon Sep 17 00:00:00 2001 From: Chris Coley <chris@codingallnight.com> Date: Sat, 30 Jun 2018 00:03:43 -0700 Subject: [PATCH] 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. --- defaults/main.yml | 7 +++++ tasks/bootstrap.yml | 66 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 63 insertions(+), 10 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 99f43ab..23329f3 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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: diff --git a/tasks/bootstrap.yml b/tasks/bootstrap.yml index a840b3f..2a66d01 100644 --- a/tasks/bootstrap.yml +++ b/tasks/bootstrap.yml @@ -1,16 +1,63 @@ --- -- 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: -- GitLab