Ansible Playbookをlocalhostを対象に実行しようとすると、以下のエラーが発生しplaybookが実行できなかった。
$ ansible-playbook -i inventory playbook.yml
PLAY [all] ***********************************************************************************************************
TASK [Gathering Facts] ***********************************************************************************************
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:(****).
Are you sure you want to continue connecting (yes/no)? yes
fatal: [localhost]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.\r\nroot@localhost: Permission denied (publickey,password,keyboard-interactive).", "unreachable": true}
PLAY RECAP ***********************************************************************************************************
localhost : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
調査したところlocalhostで実行するときには--connection local
オプションを実行時につけると良いらしい。
$ ansible-playbook -i inventory playbook.yml --connection=local
PLAY [all] ***********************************************************************************************************
TASK [Gathering Facts] ***********************************************************************************************
ok: [localhost]
TASK [helloworld : Hello World!] *************************************************************************************
ok: [localhost] => {
"msg": "Hello World!"
}
PLAY RECAP ***********************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0