Ansible – 通过堡垒瓦特/ MFA访问

在我目前的环境中,我所有的Linux服务器都只能通过启用了MFA的堡垒主机访问。

我设法让Ansible成功地通过堡垒与服务器交谈,唯一的问题是它为每个主机build立了一个新的堡垒连接,这意味着我必须input尽可能多的MFA密钥,因为我有服务器。 不好的时候 🙁

我已经尝试在我的sshconfiguration中尝试使用多路复用工作:

Host bastion ControlMaster auto ControlPath ~/.ssh/ansible-%r@%h:%p ControlPersist 5m 

不幸的是,似乎没有这样做。 任何人都可以得到一些关于如何阻止Ansible通过我的堡垒主机为其接触到的每个主机重新build立连接的提示。

谢谢!

我只是偶然发现了一篇关于运行Ansible和堡垒主机的博客文章 。

显然你需要将堡垒主机添加到控制主机ssh_config

 Host 10.10.10.* ProxyCommand ssh -W %h:%p bastion.example.com IdentityFile ~/.ssh/private_key.pem Host bastion.example.com Hostname bastion.example.com User ubuntu IdentityFile ~/.ssh/private_key.pem ControlMaster auto ControlPath ~/.ssh/ansible-%r@%h:%p ControlPersist 5m 

编辑ssh_args中的ansible.cfg

 [ssh_connection] ssh_args = -F ./ssh.cfg -o ControlMaster=auto -o ControlPersist=30m control_path = ~/.ssh/ansible-%%r@%%h:%%p 

这应该掩饰configuration的bastion部分。 对于MFA部分,这个github问题中的一些用户声称可以在Ansible之外打开的Ansible中使用ssh会话。

我打开与2FA的主机的初始连接,然后在另一个窗口运行如下所示:

 ansible-playbook thing.yml --ssh-common-args='-o ControlPath=~/.ssh/connshare' 

我手边没有一个堡垒主机,但我认为这个策略值得一试。