How to solve the {"Failed to connect to the host via ssh: Permission denied (publickey,password).\r\n", "unreachable": true} issue

I am using Ansible to create and setup new virtual machine.

after the VM is created, if I use playbook to setup VM

ansible-playbook config-vm.yml -i …/…/vms --extra-vars “target=10.150.200.30” --extra-vars “@password.json” --vault-password-file ~/vault-password.txt

Then I get this error
UNREACHABLE! => {“changed”: false, “msg”: "Failed to connect to the host via ssh: Shared connection to 10.150.200.30 closed.\r\n", “unreachable”: true}

but if I explicitly ask the password
ansible-playbook config-vm.yml -i …/…/vms --extra-vars “target=10.150.200.30” --ask-pass --ask-become-pass --ask-vault-pass

it will work.

How to solve this issue, I don’t want to type the password during setup process.

Don't use vault?
The whole point of vault is to encrypt information so you need a password to access it.

A convenient compromise between "authenticating every time" and
"storing vault passwords in plain text" is the use of wrappers scripts
that fetch the vault password from agents that run in-memory.
So you authenticate less frequently (i.e. more convenient), and don't
store vault passwords on disk in clear text (i.e. more secure).
I've successfully used this approach using GnuPG and LastPass.
LastPass has the added benefit of being able to share vault passwords
across a team (although this requires the paid version).

Dick