我有以下问题:
我正在编写用于配置NFS服务器和NFS客户端的剧本。
在同一本剧本中,我还包括其他两项任务:
CentOS_7_NFS_Server.yml和CentOS_7_NFS_Client.yml
因为我可以执行比较
的IP地址所需的任务之一远程主机
示例:
- 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
在var中:
NFS_Server: x.x.x.x
NFS_Client : y.y.y.y
我收到此错误
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
答案 0 :(得分:0)
很有可能已禁用facts的收集。当您看到错误时:
ansible_all_ipv4_addresses:变量未定义!
启用
- hosts: nfs_server_and_client
gather_facts: yes
还有另一个问题。 ansible_all_ipv4_addresses 是所有地址的列表。例如。
ansible_all_ipv4_addresses:
- 192.168.122.1
- 10.1.0.11
- 192.168.1.10
您必须选择一个或多个并将其分配给 NFS_Server 和 NFS_Client 。然后,如果 NFS_Server 和 NFS_Client 分别在列表 ansible_all_ipv4_addresses 中,则条件为test。
- 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