Dynamic IP addresses in inventory

Hello everyone,

I’ve a lot of Unifi Access Point without A-RR in DNS. So if I want to connect to the access point, I’ve to connect over the ip address, instead of using a dns name.
So I want reach the AP with the Ansible inventory, but I can’t use the range operator in ansible_host variable.

My inventory

[accesspoint]
AP[01:49].my.local ansible_host=172.16.16.[01:49]

Error code

AP01.my.local | UNREACHABLE! => {
    "changed": false,
    "unreachable": true,
    "msg": "Failed to connect to the host via ssh:  \
     ssh: Could not resolve hostname 172.16.16.[01:49]: Name or service not known"
}

Any cloue how do I connect these IPs dynamically with the inventory aliases?

Best regards
Automator

no, the range only applies to the host pattern, you CAN use jinja though

ansible_host=172.16.16.{{ inventory_hostname[2:4]}} 

or preferably using a regex

ansible_host=172.16.16.{{ inventory_hostname|regex_replace('AP(\\d+).+', '\\1') }}