--- - name: Bootstrap new host - Setup sudo hosts: all tags: bootstrap remote_user: graham gather_facts: no vars: ansible_user: graham tasks: - name: Ensure sudo is present raw: | if command -v sudo >/dev/null 2>&1; then exit 0 fi if command -v apt-get >/dev/null 2>&1; then apt-get update && apt-get install -y sudo elif command -v dnf >/dev/null 2>&1; then dnf install -y sudo elif command -v yum >/dev/null 2>&1; then yum install -y sudo elif command -v apk >/dev/null 2>&1; then apk add --no-cache sudo else echo "Unsupported package manager for sudo installation" >&2 exit 1 fi become: yes become_method: su become_user: root - name: Ensure Python 3 is present raw: | if command -v python3 >/dev/null 2>&1; then exit 0 fi if command -v apt-get >/dev/null 2>&1; then apt-get update && apt-get install -y python3 python3-apt elif command -v dnf >/dev/null 2>&1; then dnf install -y python3 elif command -v yum >/dev/null 2>&1; then yum install -y python3 elif command -v apk >/dev/null 2>&1; then apk add --no-cache python3 py3-pip else echo "Unsupported package manager for python3 installation" >&2 exit 1 fi changed_when: false become: yes become_method: su become_user: root - name: Bootstrap new host - Base configuration hosts: all tags: bootstrap remote_user: graham become: yes become_method: sudo vars: ansible_user: graham ansible_python_interpreter: /usr/bin/python3 roles: - base