How Do You Troubleshoot the Ansible Playbook Error “fatal: FAILED! => {“msg”: “The conditional check “?

Problem scenario
You run an Ansible playbook that uses a variable, but you get the message "fatal: FAILED! => {"msg": "The conditional check ...The error was: error while evaluating conditional (ansible_hostname == ):".  What should you do?

When testing a variable's value to another fixed string, put quotes around the string.  

Here is an incorrect example of a playbook using such a comparison:

      when: ansible_hostname == contintserver

Here is a correct example of an Ansible playbook using a string comparison:

      when: ansible_hostname == "contintserver"

To see more correct syntax and context, see this playbook:

- name: This is a test.
  hosts: contintserver
    - shell:  "free -m > /tmp/memory.txt"
- name: Second section.
  hosts: contintserver
    - shell: "echo  > /tmp/date.txt"
      when: ansible_hostname == "contintserver"

Leave a comment

Your email address will not be published. Required fields are marked *