LoginSignup
0

More than 5 years have passed since last update.

AnsibleでUbuntu 16.04にPython2を導入するplaybook例。冪等性やchanged ハンドリング対応

Last updated at Posted at 2019-03-24

概要

以下のplayにPython導入ずみ環境対応やchangedハンドリングを追加してみました
- Ubuntu 16.04 で ansible を使う

  • 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

参考

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0