Ansible IP地址变量远程主机
Ansible IP address variable remote hosts
我有以下问题:
我正在编写用于配置 NFS 服务器和 NFS 客户端的剧本。
在同一个剧本中,我还包括了 2 个其他任务:
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
在变量中:
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
很可能 facts 的收集被禁用了。当您看到错误时:
ansible_all_ipv4_addresses: VARIABLE IS NOT DEFINED!
启用它
- hosts: nfs_server_and_client
gather_facts: yes
还有一个问题。 ansible_all_ipv4_addresses 是 list 个 all 个地址。例如。
ansible_all_ipv4_addresses:
- 192.168.122.1
- 10.1.0.11
- 192.168.1.10
您必须选择一个或多个并将其分配给 NFS_Server 和 NFS_Client .那么条件应该是test if NFS_Server和NFS_Client分别在列表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
我有以下问题:
我正在编写用于配置 NFS 服务器和 NFS 客户端的剧本。
在同一个剧本中,我还包括了 2 个其他任务:
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
在变量中:
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
很可能 facts 的收集被禁用了。当您看到错误时:
ansible_all_ipv4_addresses: VARIABLE IS NOT DEFINED!
启用它
- hosts: nfs_server_and_client
gather_facts: yes
还有一个问题。 ansible_all_ipv4_addresses 是 list 个 all 个地址。例如。
ansible_all_ipv4_addresses:
- 192.168.122.1
- 10.1.0.11
- 192.168.1.10
您必须选择一个或多个并将其分配给 NFS_Server 和 NFS_Client .那么条件应该是test if NFS_Server和NFS_Client分别在列表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