Skip to content

Instantly share code, notes, and snippets.

@triplepoint
Last active September 28, 2018 21:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save triplepoint/9b7a7ccd5ef73ac9dcc79f664432f49b to your computer and use it in GitHub Desktop.
Save triplepoint/9b7a7ccd5ef73ac9dcc79f664432f49b to your computer and use it in GitHub Desktop.
Python 2 Check, importable Ansible playbook snippet to ensure Python 2 is available (for instance, on an Ubuntu xenial target)
---
# This task list is intended to be imported by playbooks, before any
# other tasks are performed. It lets us install Python 2 (needed by Ansible)
# before Ansible tries to call anything that would use it.
#
# Execute these tasks as the first thing in a playbook like so:
# - hosts: some-host-group
# gather_facts: false
# tasks:
# - import_tasks: _python_2_check.yml
- name: Python 2 Check | Test whether Python 2 is present
raw: test -e /usr/bin/python
register: python2_is_present
failed_when: python2_is_present.rc not in [0, 1]
changed_when: false
- name: Python 2 Check | Install Python 2, if necessary
become: true
raw: apt-get -y update && apt-get install -y python-minimal
when: python2_is_present.rc == 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment