..
Ansible 主机多网卡情况下获取IP地址
这里有一个错误用法是获取受控机器的网卡的信息,但是有多个网卡的情况下就会获取到其它的网卡地址,正确的做法如下:
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_ssh_host 这个内置变量.