# Ansible with JSON hosts file

**URL:** <https://forum.ansible.com/t/ansible-with-json-hosts-file/33458>\
**Category:** Ansible Project\
**Created:** [July 21, 2020, 9:22pm UTC](https://forum.ansible.com/t/ansible-with-json-hosts-file/33458 "2020-07-21T21:22:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mahesh\_N](https://avatars.discourse-cdn.com/v4/letter/m/977dab/32.png) [@Mahesh\_N](https://forum.ansible.com/u/Mahesh_N)\
**Post date:** [July 21, 2020, 9:22pm UTC](https://forum.ansible.com/t/ansible-with-json-hosts-file/33458/1 "2020-07-21T21:22:56Z")

</div>

Hi Team,  
I have the issue while running the Ansible playbook. There is no error with playbook, but the host.json will be in below format. the execution is happening only for one (Apple2), it is skipping (Apple1) even running with -l (limit) to apple1. Its picking the vars of Apple2.  
FYI: Both are on the same host, but need two processes running with different vars.

Any idea is appreciated!!!

{

“all”:{

“hosts”:{

},

“children”:{

“Apple1":{

“hosts”:{

"10.10”.10.1:null

},

“vars”:{

"abs\_path”:”/a/b/c”,

“Version”:“6.8.9”,

“processors”:"12”,

}

},

“Apple2”:{

“hosts”:{

"10.10”.10.1:null

},

“vars”:{

"abs\_path”:”/x/yz”,

“Version”:“6.8.9”,

“processors”:“11”,

}

}

}

}

}

Thanks

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [July 21, 2020, 9:35pm UTC](https://forum.ansible.com/t/ansible-with-json-hosts-file/33458/2 "2020-07-21T21:35:08Z")

</div>

hosts are unique in Ansible, and one thing to note is that the inventory doesn’t maintain hierarchy, like the YAML/JSON format may lead you to believe.

As such, group vars are merged down on to the hosts at inventory processing time. As such, your `vars` are applied down onto 10.10.10.1, with 1 group overwriting the other.

You can get around this by using a host alias, and then putting the address in `ansible_host` under `vars`. You could just make `Apple1` and `Apple2` those aliases, instead of making them groups:

{  
“all”: {  
“hosts”: {  
“Apple1”: {  
“ansible\_host”: “10.10.10.1”,  
“Version”: “6.8.9”,  
“abs\_path”: “/a/b/c”,  
“processors”: “12”  
},  
“Apple2”: {  
“ansible\_host”: “10.10.10.1”,  
“Version”: “6.8.9”,  
“abs\_path”: “/x/yz”,  
“processors”: “11”  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![Mahesh\_N](https://avatars.discourse-cdn.com/v4/letter/m/977dab/32.png) [@Mahesh\_N](https://forum.ansible.com/u/Mahesh_N)\
**Post date:** [July 21, 2020, 9:51pm UTC](https://forum.ansible.com/t/ansible-with-json-hosts-file/33458/3 "2020-07-21T21:51:38Z")

</div>

Thanks for the info @Matt  
I’m in need of running 5 such groups in each host, and I couldn’t make 5 alias for the single host. Is there any other work around.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [July 21, 2020, 10:02pm UTC](https://forum.ansible.com/t/ansible-with-json-hosts-file/33458/4 "2020-07-21T22:02:11Z")

</div>

You could still use groups, you just need unique hosts. So if you had 5 groups and 5 hosts, you would need 25 hosts basically. Remember that group vars merge down on the hosts, and the host is singular, so the same entry in multiple groups is the same host.
