概要
以下のplayにPython導入ずみ環境対応やchangedハンドリングを追加してみました
-
Ansible rawモジュールを使用してUbuntu 16.04にPython2を導入
- とりあえずapt決め打ち
-
rawモジュールを使用する為、gather_facts: false
-
Pythonが既に使用可能ならば、which pythonの結果より
- failed_when:, changed_when: の除外対象とする
-
Pythonの導入を行なった場合、rcを特定の値(ここでは100)とし
- failed_when: の除外対象とする
play例
- hosts: all
gather_facts: false
tasks:
- name: install python2 for Ubuntu 16.04
raw: which python || ( apt update && apt --yes install python && exit 100 )
register: result
failed_when: result.rc not in [0,100]
changed_when: result.rc != 0