I have the following YAML in an Ansible playbook:
offset: "{{ publicip | regex_replace('^.*\\.([0-9]+)$', '\\\\1') | int % (step-1) + 1 }}"
cron_minute_list: "{% for i in range(offset, 60, step) %}{{ i }},{% endfor %}"
But when I run the playbook, I get this error:
fatal: [default] => Failed to template */{{ cron_minute_list | regex_replace('.$', '') }}:
Failed to template {% for i in range(int_offset, 60, step) %}{{ i }},{% endfor %}:
an unexpected type error occurred. Error was an integer is required
I get other errors when I try using int(offset)
in the range
statement. Appending a | int
to the end of the offset
declaration makes no difference.
There seems to be no way to set the type of offset
to be an integer rather than a string. How can I fix this?
If there's another way to make such a cron schedule, so I don't have to worry about this, that would also be a good answer.
Best I can tell, you're trying to introduce a random splay to your cron minute using the IP of the machine. Ansible has a simple
random
filter that I think would be perfectly suited. Couple that with thecron
module and your playbook should be radically simpler.http://docs.ansible.com/ansible/cron_module.html http://docs.ansible.com/ansible/playbooks_filters.html#random-number-filter