I want to define an Ansible role and register dynamic variables:
---
- name: Check for {{ package }}
stat: path=/opt/packages/{{ package }}
register: "{{ package | regex_replace('-', '_') }}"
- name: Install {{ package }} {{ package_version }}
command: "custom-package-installer {{ package }} {{ package_version }}"
when: "not {{ package | regex_replace('-', '_') }}.stat.exists"
Usage looks like this:
- include: install_package.yml package=foo package_version=1.2.3
However, Ansible doesn't recognise the conditional:
TASK: [example | Install foo 1.2.3] ***********************************
fatal: [my-server] => error while evaluating conditional: not foo.stat.exists
FATAL: all hosts have already failed -- aborting
How can I define variables dynamically, expanding the {{ }}?