1

Here's my playbook.

- name: "Verify if the 'template' boolean has been set ?"  
  assert:
    that:      
      - template is defined
      - template is boolean    
    fail_msg: "'template' must be defined and be present as a boolean"

and i got the below error message,

MSG:
The conditional check 'template is boolean' failed. The error was: template error while templating string: no test named 'boolean'. String: {% if template is boolean %} True {% else %} False {% endif %}

Executing the ansible command like anisble-playbook -i ip "{'template': true}" sample.yml

How to do i fix this issue. without removing template is boolean parameter.

Prabahar S
  • 51
  • 9

1 Answers1

1
  • The parameter -e, --extra-vars is missing in your run-string
shell> ansible-playbook -i ip "{'template': true}" sample.yml

Because the first parameter without option is considered a playbook you should have seen the error message:

ERROR! the playbook: {"template": true} could not be found


  • The Jinja test boolean should always be available the same way the test defined is. I can't reproduce the problem. The playbook below
- hosts: localhost

  tasks:

    - assert:
        that:      
          - template is defined
          - template is boolean    
        fail_msg: template must be defined and type boolean

works as expected. The test will pass if the variable template is defined and boolean

shell> ansible-playbook -e '{"template": true}' pb.yml 

PLAY [localhost] ******************************************************************************

TASK [assert] *********************************************************************************
ok: [localhost] => changed=false 
  msg: All assertions passed

PLAY RECAP ************************************************************************************
localhost: ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Otherwise, the play fails

shell> ansible-playbook pb.yml 

PLAY [localhost] ******************************************************************************

TASK [assert] *********************************************************************************
fatal: [localhost]: FAILED! => changed=false 
  assertion: template is defined
  evaluated_to: false
  msg: template must be defined and type boolean

PLAY RECAP ************************************************************************************
localhost: ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
Vladimir Botka
  • 58,131
  • 4
  • 32
  • 63
  • Sorry type mistake. I haven't mentioned -e option in the ansible command. And whatever you have mentioned I tried and getting the same error `ansible-playbook -e '{"template": true}' sample.yml TASK [assert] fatal: [localhost]: FAILED! => {"msg": "The conditional check 'template is boolean' failed. The error was: template error while templating string: no test named 'boolean'. String: {% if template is boolean %} True {% else %} False {% endif %}"} ` – Prabahar S Jun 21 '23 at 08:37
  • I'm using the ansible 2.12.2 version. – Prabahar S Jun 21 '23 at 08:41
  • There must be some namespace conflict in your configuration. First, you should try to change the name of the variable `template` to something else. – Vladimir Botka Jun 21 '23 at 09:00
  • It's working. After upgrade the jinja2 module using pip command. Thanks – Prabahar S Jun 21 '23 at 09:02