はじめに
2021/01/17 に、YouTube Live で「つまずき Ansible 【Part26】ansible.cfg を触る」という配信をしました。
実際に作業しながら(ときには)エラーと戦って進めるシリーズです。
今回は、設定ファイルである ansible.cfg で、何かを設定変更する試みをしました。
設定項目一覧 Ansible Configuration Settings — Ansible Documentation
- 環境
- Ansible 2.9.16
動画
- 0:00 イントロダクション
- 2:45 設定項目一覧
- 4:15 優先順位
- 8:12 コマンドでマニュアルを見る
- 9:48 設定変更と確認方法(host_key_checking)
- 19:09 stdout_callback
- 21:39 gathering
- 25:45 ask_vault_pass
- 28:48 おわりに
■ やったこと
公式ドキュメントの確認
設定項目の一覧はこちら。
Ansible Configuration Settings — Ansible Documentation
ansible.cfg 以外にも環境変数などでも変更できるものもある。
section が [defaults] で、Key が host_key_checking なら、ansible.cfg の場合は、以下のように指定する、という見方。
[defaults] host_key_checking=値
優先順位
公式ドキュメントの通り、ansible.cfg は、配置場所によって優先順位がある。
~/.ansible.cfg だけドット付きファイル名。
どの ansible.cfg を使っているかは、ansible --version で確認できる。
(a29) [admin@gitlab stumble]$ ansible --version ansible 2.9.16 config file = /home/admin/general/vagrant/nwlab/stumble/ansible.cfg 略
ansible-config の使いみち1: 設定変更したものだけ確認する
ansible.cfg を書き換えて、ちゃんと設定値として反映できたか確認するには、ansible-config dump --only-changed が便利。デフォルトから設定変更された項目だけが表示される。
(a29) [admin@gitlab stumble]$ ansible-config dump --only-changed HOST_KEY_CHECKING(/home/admin/general/vagrant/nwlab/stumble/ansible.cfg) = False
ansible-config の使いみち2: マニュアル代わりに
ansible-config list で設定項目一覧が表示されれる。
(a29) [admin@gitlab stumble]$ ansible-config list ACTION_WARNINGS: default: true description: - By default Ansible will issue a warning when received from a task action (module or action plugin) - These warnings can be silenced by adjusting this setting to False. env: - name: ANSIBLE_ACTION_WARNINGS ini: - key: action_warnings section: defaults name: Toggle action warnings type: boolean version_added: '2.5'
設定例
host_key_checking
接続先のフィンガープリングのチェック有無の指定。デフォルトは True。
~/.ssh/known_host にない場合、サーバー相手だと以下のように問われる。
(a29) [admin@gitlab stumble]$ ansible-playbook -i inventory.ini sv.yml PLAY [sv] ****************************************************************************************************************** TASK [install] ************************************************************************************************************* The authenticity of host 'localhost (::1)' can't be established. ECDSA key fingerprint is SHA256xxx. ECDSA key fingerprint is MD5:xxx. Are you sure you want to continue connecting (yes/no)?
(配信時に、デフォルトでもチェックされることなく接続できてしまったのは、ローカルに対するPlaybookでコネクションプラグインがデフォルトのままだったからのようです。connection: ssh を明示したところいかのようになりました。ゆんぐさん、ありがとうございました!)
また、ネットワーク機器相手(試した限り IOS への ssh)だと、問われることなくエラーで終了する。
(a29) [admin@gitlab stumble]$ ansible-playbook -i inventory.ini ios_show.yml
PLAY [ios] **************************************************************************************************************************************************************************************
TASK [show] *************************************************************************************************************************************************************************************
failed: [ios02] (item=show ip route) => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "ansible_loop_var": "item", "changed": false, "item": "show ip route", "msg": "paramiko: The authenticity of host '192.168.1.12' can't be established.\nThe ssh-rsa key fingerprint is b'yyy'."}
failed: [ios01] (item=show ip route) => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "ansible_loop_var": "item", "changed": false, "item": "show ip route", "msg": "paramiko: The authenticity of host '192.168.1.11' can't be established.\nThe ssh-rsa key fingerprint is b'xxx'."}
PLAY RECAP **************************************************************************************************************************************************************************************
ios01 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
ios02 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
stdout_callback
標準出力のコールバックプラグインの指定。デフォルトは default。yaml や json が便利。
- 参考
gathering
ファクト収集の扱いの指定。デフォルトは implicit。デフォルトで無効にする場合は explicit にする。
ask_vault_pass
--ask-vault-pass 未指定時でもパスワードプロンプトを表示するかどうかの指定。デフォルトは False。
Part27 にむけて
以下のネタを検討中です。気が向いたものをやります。