LoginSignup
16
9

More than 3 years have passed since last update.

Ansible Playbookでlocalhostに接続できない問題を解決する

Posted at

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
16
9
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
16
9