とーますメモ

Ruby on Rails / Goなどの学習メモ

【Ansible】「/usr/bin/python: not found」エラーに対する処理

Ubuntu 16.04ではpython3が入っているが、
pythonが入っていないため発生するエラー。

以下のサイトが詳しい。
【小ネタ】Python3がインストールされているOSにansibleを実行する | Developers.IO
ansible pythonが無い場合の対処 - vague memory

自分の場合、Ubuntuに現段階では、phthon3には対応していないと思われるufwを
使用したかったため、サーバにpythonが存在しない場合に、pythonをインストールする
コードを以下のようにplaybookに追加した。

gather_facts: False
pre_tasks:
  - name: Install python for Ansible
    raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)
    register: output
    changed_when: output.stdout != ""
    tags: always
  - setup: # aka gather_facts

[参考]
Ansible fails with /bin/sh: 1: /usr/bin/python: not found - Stack Overflow
FS#52267 : Ansible package is running on python 3 which breaks some uncompatible modules (like ufw)