为什么提供主机别名不适用于 Ansible Inventory 文件?

Why giving a host alias does not work with an Ansible Inventory file?

生产(库存文件):

#main ansible_host=54.293.2785.210 ansible_port=22 ansible_ssh_user=ubuntu
54.293.2785.210 ansible_ssh_user=ubuntu

运行 一个临时命令:ansible all -i production -a "hostname" 有效!

但是当我取消注释第一行并注释第二行时: ansible main -i production -a "hostname" -vvvv

出现以下错误:

main | FAILED => SSH Error: ssh: Could not resolve hostname main: Name or service not known
It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue.

为什么这不起作用?

ansible_host 就是 new (>=2.0) syntax.

在此之前只是 ansible_ssh_host 但在较新版本的 Ansible (>=2.0) 中已弃用:

Ansible 2.0 has deprecated the “ssh” from ansible_ssh_user, ansible_ssh_host, and ansible_ssh_port to become ansible_user, ansible_host, and ansible_port. If you are using a version of Ansible prior to 2.0, you should continue using the older style variables (ansible_ssh_*). These shorter variables are ignored, without warning, in older versions of Ansible.

如果您使用的是早期版本的 Ansible,那么 ansible_ssh_host 应该适合您。