Ansible 使用当前机器的 host 值

这里有一个错误用法是获取受控机器的网卡的信息,但是有多个网卡的情况下就会获取到其它的网卡地址,正确的做法如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
vagrant@archlinux k8s-install $ ansible -i inventory -m debug -a "var=ansible_ssh_host" all -u vagrant -k
SSH password:
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
127.0.0.1 | SUCCESS => {
"ansible_ssh_host": "127.0.0.1"
}
192.168.0.10 | SUCCESS => {
"ansible_ssh_host": "192.168.0.10"
}
192.168.0.11 | SUCCESS => {
"ansible_ssh_host": "192.168.0.11"
}
192.168.0.12 | SUCCESS => {
"ansible_ssh_host": "192.168.0.12"
}

使用 ansible_ss_host 这个内置变量.