简体   繁体   English

Ansible:比较变量

[英]Ansible: compare variables

I am trying to compare some variables so here is my case: 我想比较一些变量,所以这是我的情况:

pg_master_ip is an ip obviously. pg_master_ip显然是一个ip。

ansible doesn't parse pg_master_ip . pg_master_ip不解析pg_master_ip

bond0.stdout is a result of an earlier register task. bond0.stdout是早期注册任务的结果。

If I could use {{ hostvars[inventory_hostname]['ansible_bond0'].ipv4.address }} I'd be happier but I don't know how. 如果我可以使用{{ hostvars[inventory_hostname]['ansible_bond0'].ipv4.address }}我会更开心,但我不知道如何。

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

Thank you for the advice in advance. 提前感谢您的建议。

Using {{ hostvars[inventory_hostname][some_variable] }} is redundant. 使用{{ hostvars[inventory_hostname][some_variable] }}是多余的。 You can just use {{ some_variable }} instead. 您只需使用{{ some_variable }} In this case it would be {{ ansible_bond0.ipv4.address }} . 在这种情况下,它将是{{ 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM