Skip to content

Instantly share code, notes, and snippets.

Created June 16, 2016 21:59
Star You must be signed in to star a gist
What would you like to do?
Get Ansible to work on bare Ubuntu 16.04 without python 2.7
# Add this snippet to the top of your playbook.
# It will install python2 if missing (but checks first so no expensive repeated apt updates)
- hosts: all
gather_facts: False
- name: install python 2
raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)
Copy link

maherio commented Feb 8, 2020

Why is the raw command necessary for this? I've been having trouble running this lately (likely due to @mahlingam's comment above), and I found that this seems to work for me:

- hosts: all
  become: true
  become_user: root
  become_method: sudo
  gather_facts: no
    - name: Install python for Ansible
        update_cache: yes
          - python-minimal
    - setup: # aka gather_facts

Just wondering if there's a reason not to do this

Copy link

Just wondering if there's a reason not to do this

Yep, I think it's simply that a target server without python installed, is unable to run normal ansible task steps. Using 'raw' side-steps the need for python.

Copy link

PS I think bootstrapping a Python 2 installation is now likely to be unnecessary, since Ansible 2.8+ will auto-detect a suitable Python interpreter to use anyway.

Copy link

If anyone is looking for a solution for Ubuntu 20.04 - change python-minimal to python2-minimal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment