ansible playbook performance tuning
ansibleでplaybookを書いていたが、大規模化するにつれ実行時間を要するようになり調査・対応を下記へ記載しておく。
以下、設定環境:ansible version2.1
・ansible.confパラメータチューニング
# cat .ansible.cfg [defaults] transport=ssh pipelining=True forks=100 fact_caching = jsonfile fact_caching_connection = /tmp/cache fact_caching_timeout = 86400 # seconds [ssh_connection] ssh_args=-o ControlMaster=auto -o ControlPersist=30m scp_if_ssh=True control_path=%(directory)s/%%h-%%r
・strategy設定(linear, free)
- linear
- 今まで(〜1.9)と同じ動作
- 全てのホストでそれぞれのタスクを次タスクに行く前に終わらせる
- 並列処理で各ホストのタスクを実施する
- デフォルトは5並列で並列数の設定が可能
- 1.9以前と同様、serialパラメータとの併用で並列数が設定出来る
- free
- ホスト間においてタイミングの調整など取らずとにかく早く終わるように実行する
playbookにstrategyを記載
# cat test.yml
---
- hosts: testhosts
become: yes
strategy: free
become_method: su
become_user: root
roles:
- td-agent
規模が大きくなる場合、playbook実行に時間を要するようになる。
上記で設定でパフォーマンス改善が見込めそう。cacheをMWにする事によりより汎用性が高まりそうではある。