Ansible:比较变量 [英] Ansible: compare variables

查看:104
本文介绍了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:比较变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆