This request as been made many times bu there is still no way around the main issues:
how to deal with multiple unknown prompts in a generic fashion
factor expiration and handling regeneration and input
factor changes across hosts or time boundries (-k is for 'all hosts' or you can set variables for specific host/groups to override), hosts are also not all accessed at same time and as the forks go through the hosts you might end up using the wrong factor (for time based ones).
Since this is not really proposing a 'solution' but that a 'solution be given' I'm going to close this proposal.
Proposal: Support SSH two factor authentication
Author: Kirill @djkerya
Date: 2021-03-24
Motivation
To make possible use connections with 2fa
Problems
ansible-playbook is stuck at ssh initialization when the server asks for the code.
Solution proposal
ansible-playbook should ask the code of the two-factor-authentication as it does with the -k parameter for password authentication.
https://github.com/ansible/ansible/issues/10065