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”
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.
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 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.
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?
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.
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).