0

Jenkins has a Boolean parameter mycheck which gets passed to ansible playbook like below:

ansible-playbook -i /var/myserver.hosts /var/testplay.yml -e mycheck=$mycheck

The above translates to the below when the checkbox is unchecked:

ansible-playbook -i /var/myserver.hosts /var/testplay.yml -e mycheck=False

cat /var/testplay.yml

- debug:
    msg: "mycheck is True"
  when: not mycheck

However, the above debug gets skipped when I was expecting the when condition to be true and print.

Can you please suggest why not mycheck is not translated to "true" and the when condition met ?

Ashar
  • 2,942
  • 10
  • 58
  • 122

1 Answers1

1

Cause: This is caused due to the datatype issue, By default, ansible treats any variable passed via extra-vars as Unicode string instead of associating a boolean class to the text that is passed.

Solution: Your initial command of execution should be modified to below ansible-playbook -i /var/myserver.hosts /var/testplay.yml -e '{ mycheck: True }'

CRDias
  • 114
  • 3
  • passed `-e '{ mycheck=false }'` but now it is giving me the the following error: `fatal: [localhost]: FAILED! => {"msg": "The conditional check 'not mycheck and file_perm == \"\"' failed. The error was: error while evaluating conditional (not mycheck and file_perm == \"\"): 'mycheck' is undefined ` – Ashar Jan 13 '21 at 15:52
  • with `-e '{ mycheck: false }'` it works while with `-e '{ mycheck=false }'` it fails. Can you suggest a solution for `-e '{ mycheck=false }'` ? – Ashar Jan 13 '21 at 15:59
  • I dont think it works that way, with respect to the syntax – CRDias Jan 13 '21 at 17:20