First, we need to set a ProxyCommand in ansible_ssh_common_args inventory variable, since any arguments specified in this variable are added to the sftp/scp/ssh command line when connecting to the relevant host(s). For example
[gatewayed]
staging1 ansible_host=10.0.2.1
staging2 ansible_host=10.0.2.2
To create a jump host for these we need to add a command in ansible_ssh_common_args
ansible_ssh_common_args: '-o ProxyCommand="ssh -W %h:%p -q [email protected]"'
In this way whenever we will try to connect to any host in the gatewayed group ansible will append these arguments to the command line.