5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ansible.cfgで書きたい設定の辿り方メモ

Posted at

はじめに

ansible.cfgに環境変数ベタ書きしようとした間抜けな私へ。

環境は以下。

  • CentOS Linux release 8.0.1905 (Core)
  • ansible 2.9.2

設定したい項目を特定する

公式とか、ansible-config listから、お目当てのセクションを特定する。
例えば、ssh接続時のホストキーチェックを無効にしたいと思ったとき、HOSTとかKEYとかCHECKとかの
ワードで検索して、それっぽいのを探す。

$ ansible-config list

今回の場合はこれ。

HOST_KEY_CHECKING:
  default: true
  description: Set this to "False" if you want to avoid host key checking by the underlying
    tools Ansible uses to connect to the host
  env:
  - name: ANSIBLE_HOST_KEY_CHECKING
  ini:
  - key: host_key_checking
    section: defaults
  name: Check host keys
  type: boolean

書式を確認して設定する

セクションを特定したら、ansible.cfgはini形式なので、iniのリストに注目する。
keyhost_key_checkingsectiondefaultstypebooleanと書いてあるので、
ini形式で下記のように記述する。

ansible.cfg
[defaults]
host_key_checking=false

上記から設定を足したくなった時、sectiondefaultsなら、keyだけ書き足してあげれば良いし、
違うなら、同じようにブラケットで囲ってセクションごと追加してあげる必要がある。

ちなみに、envは環境変数なので、.bashrcとかに記述する場合は、下記で良い。
ini形式でないので、セクションとか要らない。

ANSIBLE_HOST_KEY_CHECKING=false

設定が反映されているか確認する

デフォルトから変更されている設定値だけ確認できれば良いので、下記コマンドが楽。

$ ansible-config dump --only-changed

参考

公式
GitHub

5
1
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
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?