Hello again,
I have the following inventory:
[physical]
somehost.example.com vpn_ip=10.0.1.1
anotherhost.example.com vpn_ip=10.0.2.1
and a task:
hosts: vpn_hub.example.com
tasks:
- action: template src=templates/openvpn-server-ccd.conf dest=/home/ansible/ccd/$item
with_items: ${groups.physical}
only_if: “$hostvars[‘$item’][‘vpn_ip’]”
Right now ansible explodes while trying to evaluate the only_if condition (KeyError: ‘somehost.example.com’).
Is it possible to somehow limit the rule to only generate configs for hosts that have the vpn_ip variable set, or should I make a dedicated group for that? My inventory is actually a script so that’s not too big a deal, but I’d rather keep this logic in one place. Accessing {{ hostvars[item].vpn_ip }} in the template works fine and I feel I’m 99% there, I just get redundant files for hosts without vpn_ip set.
BTW, is there some documentation about how only_if actually works, i.e. what’s the exact format ($foo isn’t really Python) and what are the available variables?
Thanks,
Grzegorz Nosek