The host  host1.example.com <http://host1.example.com/> is listed in both group 
A and group B - the only difference is the value of the variable ‘lhost’. 
Ansible is executing on the correct host, host1.example.com 
<http://host1.example.com/>, but with the variable value from the list ing 
group B. See 
https://docs.ansible.com/ansible/devel/user_guide/intro_inventory.html#how-variables-are-merged
 
<https://docs.ansible.com/ansible/devel/user_guide/intro_inventory.html#how-variables-are-merged>
 for information on how Ansible applies variable values. 

If that’s a typo and they are different hosts, just correct the inventory 
entries and the problem will solve itself. If for some reason you want two 
entries in your inventory for hte same host, you can still give them different 
aliases - host1on1010 and host1on22010. Or you can store the variable values in 
a playbook or vars file and select the correct one at run time.

Hope this helps,
Alicia

> On Aug 17, 2020, at 9:17 AM, Abhishek Sharma <[email protected]> wrote:
> 
> 
> updated command is 
> 
> # ansible -i inventory A -m shell -a "ls -l /tmp/{{ lhost }}" --limit 
> host1.example.com
> 
> 
> On Monday, August 17, 2020 at 7:46:00 PM UTC+5:30 Abhishek Sharma wrote:
> Hi
> 
> I have an inventory defined as below:
> 
> [A]
> host1.example.com <http://host1.example.com/> lhost=1010
> host2.example.com <http://host2.example.com/> lhost=1110
> 
> [B]
> host1.example.com <http://host1.example.com/> lhost=2010
> 
> now when i run below command on group A for host1.example.com 
> <http://host1.example.com/> ansible picks up the host in group B
> 
> # ansible -i inventory A -m shell -a "ls -l /tmp/{{ lhost }}"
> 
> output
> 
> ls: no such file or directory /tmp/2010
> 
> expected:  Ansible should execute on host1 in group A and not group B
> 
> Is this behaviour intentional or am i running into some bug or is there 
> something wrong with the command execution.
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> <mailto:[email protected]>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/cc567b0a-8095-4c1b-8a3b-85c11f2a4d34n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/ansible-project/cc567b0a-8095-4c1b-8a3b-85c11f2a4d34n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/C8395702-061C-4215-AA49-442A606FE532%40redhat.com.

Reply via email to