Есть local fact, который выдаёт следующие значения:
ansible gw79 -m setup -a "filter=ansible_local"
gw79 | success >> {
"ansible_facts": {
"ansible_local": {
"ipmi": {
"lan_1": {
"AuthTypeEnable": "Callback:MD2MD5PASSWORD",
"AuthTypeSupport": "NONEMD2MD5PASSWORD",
"BMCARPControl": "ARPResponsesEnabled,GratuitousARPDisabled",
"BackupGatewayIP": "0.0.0.0",
"BackupGatewayMAC": "00:00:00:00:00:00",
"CipherSuitePrivMax": "aaaaXXaaaXXaaXX",
"DefaultGatewayIP": "0.0.0.0",
"DefaultGatewayMAC": "00:00:00:00:00:00",
"IPAddress": "10.10.10.100",
"IPAddressSource": "StaticAddress",
"IPHeader": "TTL=0x00Flags=0x00Precedence=0x00TOS=0x00",
"MACAddress": "00:25:90:9e:ca:c7",
"RMCP+CipherSuites": "1,2,3,6,7,8,11,12",
"SNMPCommunityString": "public",
"SetinProgress": "SetComplete",
"SubnetMask": "255.255.255.0",
"qVLANID": "7",
"qVLANPriority": "0"
}
}
}
},
"changed": false
}
Задачи из роли:
- name: set ipmi vlan
command: ipmitool lan set 1 vlan id "{{ ipmi.vlan }}"
when: ansible_local.ipmi.lan_1.qVLANID != ipmi.vlan
- name: set ipmi address
command: ipmitool lan set 1 ipaddr "{{ ipmi.address }}"
when: ansible_local.ipmi.lan_1.IPAddress != ipmi.address
- name: set ipmi netmask
command: ipmitool lan set 1 netmask "{{ ipmi.netmask }}"
when: ansible_local.ipmi.lan_1.SubnetMask != ipmi.netmask
- name: set ipmi gateway
command: ipmitool lan set 1 defgw ipaddr "{{ ipmi.gw }}"
when: ansible_local.ipmi.lan_1.DefaultGatewayIP != ipmi.gw
- name: debug
debug: msg="{{ ansible_local.ipmi.lan_1.qVLANID }}"_"{{ ipmi.vlan }}"_"{{ ansible_local.ipmi.lan_1.IPAddress }}"_"{{ ipmi.address }}"_"{{ ansible_local.ipmi.lan_1.SubnetMask }}"_"{{ ipmi.netmask }}"_"{{ ansible_local.ipmi.lan_1.DefaultGatewayIP }}"_"{{ ipmi.gw }}"
Вывод ansible-playbook:
ansible-playbook playbook/site.yml --tags ipmi
PLAY [gw-region] **************************************************************
GATHERING FACTS ***************************************************************
ok: [gw79]
TASK: [ipmi | set ipmi vlan] **************************************************
changed: [gw79]
TASK: [ipmi | set ipmi address] ***********************************************
changed: [gw79]
TASK: [ipmi | set ipmi netmask] ***********************************************
skipping: [gw79]
TASK: [ipmi | set ipmi gateway] ***********************************************
skipping: [gw79]
TASK: [ipmi | debug] **********************************************************
ok: [gw79] => {
"item": "",
"msg": "7_7_10.10.10.100_10.10.10.100_255.255.255.0_255.255.255.0_0.0.0.0_0.0.0.0"
}
PLAY RECAP ********************************************************************
gw79 : ok=4 changed=2 unreachable=0 failed=0
То есть для двух заданий - netmask и gateway - conditional работает как надо, а для других двух - не работает, и они выполняются всегда. Хотя из вывода debug явно видно, что значения одинаковые.
Где я не прав?
Традиционно, sudo cast
val-amart
З.Ы. А можно ли как-нибудь запихивать на хост local fact, а только потом делать GATHERING FACTS? Или хотя бы принудительно их получение перезапускать?