在每个环境中configurationSSH凭据

我试图找出如何分别configuration与Ansible生产和分期环境的SSH凭据。 我知道你可以通过将-i--inventory-fileparameter passing给--inventory-file ansible-playbook命令来分别使用不同的库存文件来configuration服务器IP地址和主机名。 但是,我没有看到ansible.cfg这样的选项。 目前,凭证位于/etc/ansible/ansible.cfg如下所示:

 [defaults] private_key_file=/home/caleb/.ssh/staging_key.pem remote_user=ubuntu sudo_user=root gathering=explicit 

我如何configuration多个SSH凭证,一个用于生产,一个用于分段?

似乎我的第一个答案是不完全正确的。 虽然当然可以像下面描述的那样在.ssh/config解决这个问题,但Ansibles 行为库存参数似乎也是可能的。

您应该(根据文档)能够定义清单中的密钥文件和用户,无论是主机还是每个组。

每组定义:

 [some_hosts] host1.foo host2.foo [some_hosts:vars] ansible_ssh_user=ubuntu ansible_ssh_private_key_file=/home/caleb/.ssh/staging_key.pem 

每个主机的定义:

 [some_hosts] host1.foo ansible_ssh_user=ubuntu ansible_ssh_private_key_file=/home/caleb/.ssh/staging_key.pem host2.foo ansible_ssh_user=another_user ansible_ssh_private_key_file=/home/caleb/.ssh/production_key.pem 

但是您可以在.ssh/config定义多个主机组,并且每个组可以具有关于密钥和用户的单独设置。

这是一个简单的例子

 #Example with a wildcard Host *.foo.com user ubuntu IdentityFile /home/caleb/.ssh/staging_key.pem #Example with multiple hostnames Host hostname.one hostname.two hostname.three user other_user IdentityFile /home/caleb/.ssh/production_key.pem 

你也可以定义一个默认值,稍后用更详细的设置覆盖它。

 Host * user defaut_username Host somehost user special_username