本文介绍了Ansible:比较变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试比较一些变量,所以这是我的情况:

I am trying to compare some variables so here is my case:

pg_master_ip 显然是一个ip.

ansible 不解析 pg_master_ip.

ansible doesn't parse pg_master_ip.

bond0.stdout 是早期注册任务的结果.

bond0.stdout is a result of an earlier register task.

如果我可以使用 {{ hostvars[inventory_hostname]['ansible_bond0'].ipv4.address }} 我会更开心,但我不知道如何.

If I could use {{ hostvars[inventory_hostname]['ansible_bond0'].ipv4.address }} I'd be happier but I don't know how.

- name: pgsql and pgpool initiate master
  include: master.yml
  when: bond0.stdout == '{{pg_master_ip}}'

提前感谢您的建议.

推荐答案

使用 {{ hostvars[inventory_hostname][some_variable] }} 是多余的.你可以使用 {{ some_variable }} 代替.在这种情况下,它将是 {{ ansible_bond0.ipv4.address }}.如果您想查看默认事实的完整列表,请查看设置模块.

Using {{ hostvars[inventory_hostname][some_variable] }} is redundant. You can just use {{ some_variable }} instead. In this case it would be {{ ansible_bond0.ipv4.address }}. If you want a full list of your default facts check out the setup module.

ansible $SERVER -m setup

这是您的条件任务的外观

Here's how your conditional task should look

- name: pgsql and pgpool initiate master
  include: master.yml
  when: ansible_bond0.ipv4.address == pg_master_ip

这篇关于Ansible:比较变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 03:41