LoginSignup
3
3

More than 5 years have passed since last update.

Ansibleでsudoパスワード対話入力を止める方法とansible.cfgの上書き方法

Posted at

Ansible実行自体を自動化したい、でもsudoパスワードを対話入力したくない。
そんなときは、ansible_become_pass変数にパスワードを設定する必要があります。

ただし、ansible.cfgbecome_ask_passTrueになっていると、パスワードを対話入力する必要があります。
この変数は残念ながら実行オプション--extra-varsやその他ansible内で上書きしても効果がありません。
コマンド中に実行される__init__.pyの早い段階でこの変数が使われるためです。

パスワードを聞かれないようにするため、環境ごとにansible.cfgを上書きしたり、
別のansible.cfgを読み込ませる方法もありますが、
環境変数ANSIBLE_BECOME_ASK_PASSを使って上書きする方法が簡単です。

ansible.cfgの内容はほとんどが環境変数で上書きすることができます。
上書きできる変数の種類は今のところドキュメントがなく、
ソースコード(constants.py)に書いてあるだけなので、必要な変数を探しましょう。
URLは以下です。
https://github.com/ansible/ansible/blob/devel/lib/ansible/constants.py

参考URL
ansible.cfgの公式ドキュメント

3
3
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
3
3