I have the following problem:
I'm writing a playbook for configuring NFS server and NFS client.
in the same playbook, I include 2 other tasks :
CentOS_7_NFS_Server.yml and CentOS_7_NFS_Client.yml
for I can execute one of the tasks I need to compare the IP address of
the remote hosts
Example :
- include: CentOS_7_NFS_Server.yml
when: ansible_all_ipv4_addresses == NFS_Server
- include: CentOS_7_NFS_Client.yml
when: ansible_all_ipv4_addresses == NFS_Client
in the var :
NFS_Server: x.x.x.x
NFS_Client : y.y.y.y
I got this error
FAILED! => {"msg": "The conditional check 'ansible_all_ipv4.address
== NFS_Client' failed. The error was: error while evaluating
conditional (ansible_all_ipv4.address == NFS_Client):
'ansible_all_ipv4' is undefined\n\nThe error appears to have been
in
Very probably the collecting of the facts is disabled. when you see the error:
ansible_all_ipv4_addresses: VARIABLE IS NOT DEFINED!
Enable it
- hosts: nfs_server_and_client
gather_facts: yes
There is one more problem. ansible_all_ipv4_addresses is list of all addresses. For example.
ansible_all_ipv4_addresses:
- 192.168.122.1
- 10.1.0.11
- 192.168.1.10
You'll have to pick one, or more and assign it to NFS_Server and NFS_Client . Then the condition shall test if NFS_Server and NFS_Client , respectively, is in the list ansible_all_ipv4_addresses .
- include: CentOS_7_NFS_Server.yml
when: NFS_Server in ansible_all_ipv4_addresses
- include: CentOS_7_NFS_Client.yml
when: NFS_Client in ansible_all_ipv4_addresses
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.