If you set ask_pass and ssh_args as shown below, then ansible should ask you for the password at the beginning once and use this password whenever auth with the public key does not work.
[defaults] ask_pass = True [ssh_connection] ssh_args = -o PubkeyAuthentication=yes -o PasswordAuthentication=yes -o ControlMaster=auto -o ControlPersist=60s
This is still not a complete solution: Catch being (AFAIK) ansible uses sshpass , so the password that it collected from you at the beginning will be the only password it will use and it will not work if you have different passwords for different machines . :-)
The only other hack I can think of is to replace /usr/bin/ssh (or depending on your opensh ssh used by the user) with a script that will clothe the logic of reading the password from some flat file, if necessary, I a suspicious user may hide tty so that your script cannot read the password from stdin.
source share