# Dynamic IP addresses in inventory

**URL:** <https://forum.ansible.com/t/dynamic-ip-addresses-in-inventory/43596>\
**Category:** Get Help\
**Tags:** inventory, network, linux\
**Created:** [June 27, 2025, 11:53am UTC](https://forum.ansible.com/t/dynamic-ip-addresses-in-inventory/43596 "2025-06-27T11:53:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Automator](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@Automator](https://forum.ansible.com/u/Automator)\
**Post date:** [June 27, 2025, 11:53am UTC](https://forum.ansible.com/t/dynamic-ip-addresses-in-inventory/43596/1 "2025-06-27T11:53:14Z")

</div>

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**

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

```

**Error code**

```auto
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

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [June 27, 2025, 3:27pm UTC](https://forum.ansible.com/t/dynamic-ip-addresses-in-inventory/43596/2 "2025-06-27T15:27:33Z")

</div>

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

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

```

or preferably using a regex

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

```
