說明
我們用ansible的facts變量獲取系統(tǒng)的信息是最方便的. 但是我們的服務(wù)器有存在多ip的情況.自己看一下
ansible 192.168.10.106 -m setup|more
看輸出需要獲取什么值
"ansible_facts": {
"ansible_all_ipv4_addresses": [
"192.168.10.106",
"192.168.10.69",
"192.168.10.218"
],
------------------------------------------------------------
"ansible_default_ipv4": {
"address": "192.168.10.106",
"alias": "ens192",
----------------------------------------------------------
"ansible_ens192": {
"active": true,
"device": "ens192",
"ipv4": {
"address": "192.168.10.106",
"broadcast": "192.168.10.255",
"netmask": "255.255.255.0",
"network": "192.168.10.0"
},
"ipv4_secondaries": [
{
"address": "192.168.10.69",
"broadcast": "192.168.10.255",
"netmask": "255.255.255.0",
"network": "192.168.10.0"
},
{
"address": "192.168.10.218",
"broadcast": "192.168.10.255",
"netmask": "255.255.255.0",
"network": "192.168.10.0"
}
所以獲取ip的值就用對應(yīng)的就可以了
ansible_all_ipv4_addresses #適用于多ip, 輸出[u'192.168.10.106', u'192.168.10.69', u'192.168.10.218'], 如果是docker幾十個(gè)ip,也很煩.
ansible_default_ipv4[address] #適用單ip
ansible_ens192[ipv4][address] #因?yàn)楹途W(wǎng)卡綁定,多系統(tǒng)版本的時(shí)候不通用