diff --git a/defaults/main.yml b/defaults/main.yml index 99f43ab113b92c6484b94a74c8b5a5f5635c7ae5..23329f3fc1d15ce42064a2a0ed558776e990445b 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 a840b3fa9fecfd73592446bc4ae8d1bed617ab78..2a66d01cdc7de22ac46f6c2c22bba549e292c6d6 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: