Register Variable in Ansible
i think this is related to this issue: https://github.com/ansible/ansible/issues/3460
Seems to be fixed now in current dev version of ansible.
Mario López
Updated on June 04, 2022Comments
-
Mario López almost 2 years
Hi I'm new in Ansible and I'm having some problems using registered variables.
The problem is that I have multiple server with different operating systems.
I use roles to separate them, but in a case where there are no servers of one kind a conditional gives me an error saying that I must put an expression that evaluates to True or False.
This is the code with the problem.
- 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'"
The error that gives me is this one:
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
I already tried these ones: when: sources.stdout is defined and source.stdout == a only_if: sources.stdout is defined and source.stdout == a
And this gives me the same error.
I'm Using Ansible 1.3 in Ubuntu 13.04 To check this out I used ansible --version
Hope you can help me. Greetings