# Execute playbook against ansible\_host without using hostname - AWX

**URL:** <https://forum.ansible.com/t/execute-playbook-against-ansible-host-without-using-hostname-awx/2446>\
**Category:** Get Help\
**Tags:** awx\
**Created:** [November 18, 2023, 6:42am UTC](https://forum.ansible.com/t/execute-playbook-against-ansible-host-without-using-hostname-awx/2446 "2023-11-18T06:42:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![manojfzev](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@manojfzev](https://forum.ansible.com/u/manojfzev)\
**Post date:** [November 18, 2023, 6:42am UTC](https://forum.ansible.com/t/execute-playbook-against-ansible-host-without-using-hostname-awx/2446/1 "2023-11-18T06:42:53Z")

</div>

Hi All,

I am using ansible awx and I have a requirement like this. I have a set of servers imported using the VM name, and inside of the variables, I have defined ansible\_host: VM IP address. How can I target ansible\_host(IP address of the VM) instead of the VM name. Because most of the ppl in our org only visible the IP address, not the VM name. I tried to define the IP address in the limit filed but it’s failing with the message “Could not match supplied host pattern ignoring : 10.x.x.x”

---

<div class="post-metadata">

**Author:** ![TheSpy0](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/thespy0/32/496_2.png) [@TheSpy0](https://forum.ansible.com/u/TheSpy0)\
**Post date:** [November 18, 2023, 8:01am UTC](https://forum.ansible.com/t/execute-playbook-against-ansible-host-without-using-hostname-awx/2446/2 "2023-11-18T08:01:13Z")

</div>

Might try using aliases. Add `ansible_host: <ip address>` as a host variable in your inventory.  
[https://docs.ansible.com/ansible/latest/inventory\_guide/intro\_inventory.html#inventory-aliases](https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html#inventory-aliases)

Hope that helps.

---

<div class="post-metadata">

**Author:** ![manojfzev](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@manojfzev](https://forum.ansible.com/u/manojfzev)\
**Post date:** [November 18, 2023, 8:32am UTC](https://forum.ansible.com/t/execute-playbook-against-ansible-host-without-using-hostname-awx/2446/3 "2023-11-18T08:32:45Z")

</div>

Hello, thank you for the quick reply however I already defined ansible\_host as a variable inside the host but when I try to limit the IP in the AWX template I get the “Could not match supplied host pattern ignoring : 10.x.x.x” error.

---

<div class="post-metadata">

**Author:** ![wa\_schaly](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/wa_schaly/32/1079_2.png) [@wa\_schaly](https://forum.ansible.com/u/wa_schaly)\
**Post date:** [November 19, 2023, 9:58am UTC](https://forum.ansible.com/t/execute-playbook-against-ansible-host-without-using-hostname-awx/2446/4 "2023-11-19T09:58:18Z")

</div>

can you use the way we did in the ‘good old days’ by using /etc/hosts ?

---

<div class="post-metadata">

**Author:** ![TheSpy0](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/thespy0/32/496_2.png) [@TheSpy0](https://forum.ansible.com/u/TheSpy0)\
**Post date:** [November 19, 2023, 8:06pm UTC](https://forum.ansible.com/t/execute-playbook-against-ansible-host-without-using-hostname-awx/2446/5 "2023-11-19T20:06:36Z")

</div>

Did a little bit of research, and it looks like it will not be possible to use the IP address to refer to a host with the dynamic inventory that you’re using. According to the [Limitation of patterns](https://docs.ansible.com/ansible/latest/inventory_guide/intro_patterns.html) section of the Ansible documentation, if an alias is defined (host1 in the example) then the IP address cannot be used to refer to a host in the inventory. An inventory of only IP addresses would need to be created to be able to do want you want.

---

<div class="post-metadata">

**Author:** ![manojfzev](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@manojfzev](https://forum.ansible.com/u/manojfzev)\
**Post date:** [November 20, 2023, 5:42pm UTC](https://forum.ansible.com/t/execute-playbook-against-ansible-host-without-using-hostname-awx/2446/6 "2023-11-20T17:42:44Z")

</div>

Thank you everyone for the replies. @TheSpy0 Yeah, it seems to be the only option to go with the IP address.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [November 22, 2023, 8:52pm UTC](https://forum.ansible.com/t/execute-playbook-against-ansible-host-without-using-hostname-awx/2446/7 "2023-11-22T20:52:17Z")

</div>

Maybe I’m missing something, but outside of AWX, if I create this one-line inventory source called `invx.ini`:

```auto
host_192.168.254.246 ansible_host=192.168.254.246

```

then I can run

```auto
$ ansible host_192.168.254.246 -i invx.ini -m setup

```

So, if you get “a set of servers imported” (into AWX?) and have their IP addresses, I believe you could take that set and create/update, with a playbook, an inventory source that’s known to AWX. Then the people in your organization who have the IP address of a relevant host could target “`host_<ip address>`”. There’s a little work up front to keep the `host_`-prefixed inventory source up-to-date, but maybe that’s okay?

---

<div class="post-metadata">

**Author:** ![manojfzev](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@manojfzev](https://forum.ansible.com/u/manojfzev)\
**Post date:** [November 24, 2023, 8:09pm UTC](https://forum.ansible.com/t/execute-playbook-against-ansible-host-without-using-hostname-awx/2446/8 "2023-11-24T20:09:27Z")

</div>

Hey, thanks for the reply. I was thinking the same thing, but if we are targeting 100+ hosts or more than that at the same time, then it will be troublesome to generate this pattern for all the hosts, and if someone makes a mistake when generating a pattern, the playbook will execute against wrong targets.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [November 25, 2023, 5:41pm UTC](https://forum.ansible.com/t/execute-playbook-against-ansible-host-without-using-hostname-awx/2446/9 "2023-11-25T17:41:31Z")

</div>

If you define a `bash` function like this:

```sh
limit_by_ip ()
{ 
    local -a hosts_by_ip=($(for h in "$@"; do echo "host_$h"; done));
    ( IFS=,;
    printf " --limit=%s\n" "${hosts_by_ip[*]}" )
}

```

then this command

```sh
ansible-playbook foo.yml $(limit_by_ip 12.23.34.45 56.34.56.34 34.23.12.34) -v -bK

```

expands to this:

```sh
ansible-playbook foo.yml --limit=host_12.23.34.45,host_56.34.56.34,host_34.23.12.34 -v -bK

```

But if you’ve got a situation that requires people to make no mistakes when entering a hundred or more IP addresses — regardless of the format — then you need to change that situation.

Since you’d be creating an inventory source file in advance, surly you can concoct some reasonable groups to put these hosts into, groups with names that make more sense than their VM names (your original problem) and much easier to enter without mistakes than IP addresses (your more recent, and in my opinion, very real, problem).
