Ansibleの3:ansible.cfg構成説明


Ansibleがデフォルトでインストールされた後、ansibleのホストのデフォルト構成部分を定義するプロファイル/etc/ansible/ansible.cfgがあります.デフォルトでパスワードを入力する必要があるかどうか、sudo認証を開くかどうか、action_pluginsプラグインの場所、hostsホストグループの場所、log機能をオンにするかどうか、デフォルトポート、keyファイルの場所など.
具体的には以下の通りです.
    [defaults]
   # some basic default values...
   hostfile       = /etc/ansible/hosts   \\ hosts
   # library_path = /usr/share/my_modules/
   remote_tmp     = $HOME/.ansible/tmp
   pattern        = *
   forks          = 5
   poll_interval  = 15
   sudo_user      = root  \\ sudo
   #ask_sudo_pass = True  \\ ansible ssh
   #ask_pass      = True  \\ ansible sudo
   transport      = smart
   remote_port    = 22
   module_lang    = C
   gathering = implicit
   host_key_checking = False    \\ ansible
   log_path    = /var/log/ansible.log \\ 。chown -R root:root ansible.log
   system_warnings = False    \\ ansible ,
   # set plugin path directories here, separate with colons
   action_plugins     = /usr/share/ansible_plugins/action_plugins
   callback_plugins   = /usr/share/ansible_plugins/callback_plugins
   connection_plugins = /usr/share/ansible_plugins/connection_plugins
   lookup_plugins     = /usr/share/ansible_plugins/lookup_plugins
   vars_plugins       = /usr/share/ansible_plugins/vars_plugins
   filter_plugins     = /usr/share/ansible_plugins/filter_plugins
   fact_caching = memory
   [accelerate]
   accelerate_port = 5099
   accelerate_timeout = 30
   accelerate_connect_timeout = 5.0
   # The daemon timeout is measured in minutes. This time is measured
   # from the last activity to the accelerate daemon.
   accelerate_daemon_timeout = 30

以前に接続されていなかったホストを連結する場合、次のエラーが発生しました.
ansible test -a 'uptime'
   192.168.1.1| FAILED =>Using a SSH password instead of a key is not possible because HostKey checking is enabled and sshpass does not support this.Please add this host's fingerprint to your known_hosts file to manage this host.
   192.168.1.2 | FAILED => Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this host's fingerprint to your known_hosts file to manage this host.

本機での~/.ssh/known_hostsファイルにはfingerprint key列があり、sshが最初に接続されたとき、key文字列を  ~/.ssh/known_hostsファイルにあります.
方法1:
ssh接続を行う場合、-oパラメータを使用してStrictHostKeyCheckingをnoに設定し、ssh接続を使用する場合、最初の接続時にyes/no部分を入力させるヒントを避けることができます.ansible.cfgプロファイルを表示すると、次のようになります.
[ssh_connection]
# ssh arguments to use
# Leaving off ControlPersist will result in poor performance, so use
# paramiko on older platforms rather than removing it
#ssh_args = -o ControlMaster=auto -o ControlPersist=60s

ssh_を有効にできますArgsセクションでは、次の構成を使用して、上記のエラーを回避します.
ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no

方法2:
ansible.cfgプロファイルでは、次の構成も表示されます.
# uncomment this to disable SSH key host checking
host_key_checking = False

デフォルトhost_key_checkingセクションはコメントであり、行を開いたコメントを探すことで、sshをスキップした最初の接続プロンプト検証セクションも実現できます.しかし、実際のテストでは、効果がないようで、使用方法1をお勧めします.
その他
デフォルトansibleが実行されている場合、ログはファイルに出力されませんが、ansible.cfgプロファイルでは次のようになります.
log_path = /var/log/ansible.log

デフォルトlog_pathこの行は注釈で、その行の注釈を開き、すべてのコマンドが実行されると、/var/log/ansible.logファイルにログが出力されます.