Variable Issues in Ansible

Variable Issues in Ansible

This will be a short post today, feeling pretty dumb. Just learned the hard way that Ansible variable names can not start with numbers. It even says so in the first line of the documentation on variables: https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#creating-valid-variable-names

You’ll get some pretty weird output if you try and start them with numbers. Basically it parses the number as an integer, which removes it from the jinja templating, so a variable like this: `1variable` would end up templated like `variable`, which of course probably doesn’t exist. You might also get errors about jinja templating, and not including brackets {{ }}. Errors were pretty nondescript.

Learn from my mistakes, don’t do this! Hopefully this helps someone scratching their head for an hour like I did.

Leave a Reply

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