嗨,我是 Ansible 的新手,我在使用注册变量时遇到了一些问题。
问题是我有多个具有不同操作系统的服务器。
我使用角色来分隔它们,但是在没有一种服务器的情况下,条件会给我一个错误,说我必须放置一个计算结果为 True 或 False 的表达式。
这是有问题的代码。
- name: Checking if Sources are Available
action: shell echo a$(cat /etc/apt/sources.list | grep $(echo 'http://url/${ansible_distribution}/stable' | tr "[:upper:]" "[:lower:]" ))
register: sources
ignore_errors: True
- name: Adding source.
action: shell echo "deb http://url/${ansible_distribution}/stable ${ansible_lsb.codename} main" | tr "[:upper:]" "[:lower:]" >> /etc/apt/sources.list
when: "ansible_os_family == 'RedHat' and sources.stdout == 'a'"
给我的错误是这个:
fatal: [192.168.1.114] => Conditional expression must evaluate to True or False: ({% if ansible_os_family == 'RedHat' and sources.stdout == 'a' %} True {% else %} False {% endif %}) and ({% if ansible_os_family == 'Debian' %} True {% else %} False {% endif %})
fatal: [192.168.1.141] => Conditional expression must evaluate to True or False: ({% if ansible_os_family == 'RedHat' and sources.stdout == 'a' %} True {% else %} False {% endif %}) and ({% if ansible_os_family == 'Debian' %} True {% else %} False {% endif %})
FATAL: all hosts have already failed -- aborting
我已经尝试过这些: when: sources.stdout is defined and source.stdout == a only_if: sources.stdout is defined and source.stdout == a
这给了我同样的错误。
我在 Ubuntu 13.04 中使用 Ansible 1.3 为了检查这一点,我使用了 ansible --version
希望您能够帮助我。问候