Ansible integer variables in YAML

Question:

I’m using Ansible to deploy a webapp. I’d like to wait for the application to be running by checking that a given page returns a JSON with a given key/value.

I want the task to be tried a few times before failing. I’m therefore using the combination of until/retries/delay keybwords.

Issue is, I want the number of retries to be taken from a variable. If I write :

I fall into the usual Yaml Gotcha (http://docs.ansible.com/YAMLSyntax.html#gotchas).

If, instead, I write:

I’m being said the value is not an integer.

ValueError: invalid literal for int() with base 10: ‘{{apache_test_retries}}’

Here is my full code:

Any idea on how to work around this issue? Thanks.

Answer:

I had the same issue and tried a bunch of things that didn’t work so for some time I just worked around without using a variable but found the answer so for everyone who has it.

Daniels solution indeed should work:

However, if you are running a little older version of Ansible it won’t work. So make sure you update Ansible. I tested on 1.8.4 and it works and it doesn’t on 1.8.2

This was the original bug on ansible:
https://github.com/ansible/ansible/issues/5865

Leave a Reply