---
# Set machine up to be able to run ansible playbooks.

- name: check if python is installed (as required by ansible modules)
  raw: test -e /usr/bin/python
  register: is_python_installed
  failed_when: is_python_installed.rc not in [0, 1]
  changed_when: false  # never mutates state.

- name: install python if missing (as required by ansible modules)
  when: is_python_installed|failed  # skip otherwise
  raw: (test -e /usr/bin/apt-get && apt-get install -y python-minimal) || (test -e /usr/bin/yum && yum install -y python)
  changed_when: is_python_installed.rc == 1

- name: check if lsb_release is installed (as required for ansible facts)
  raw: test -e /usr/bin/lsb_release
  register: is_lsb_release_installed
  failed_when: is_lsb_release_installed.rc not in [0, 1]
  changed_when: false  # never mutates state.

- name: install lsb_release if missing (as required for ansible facts)
  when: is_lsb_release_installed|failed  # skip otherwise
  raw: (test -e /usr/bin/apt-get && apt-get install -y lsb_release) || (test -e /usr/bin/yum && yum install -y lsb_release)
  changed_when: is_lsb_release_installed.rc == 1

- setup:  # gather 'facts', i.e. compensates for the above 'gather_facts: false'.
