# Ansible ignores line from my inventory file

**URL:** <https://forum.ansible.com/t/ansible-ignores-line-from-my-inventory-file/40022>\
**Category:** Get Help\
**Created:** [February 3, 2025, 6:47pm UTC](https://forum.ansible.com/t/ansible-ignores-line-from-my-inventory-file/40022 "2025-02-03T18:47:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lost\_in\_ansible](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@lost\_in\_ansible](https://forum.ansible.com/u/lost_in_ansible)\
**Post date:** [February 3, 2025, 6:47pm UTC](https://forum.ansible.com/t/ansible-ignores-line-from-my-inventory-file/40022/1 "2025-02-03T18:47:44Z")

</div>

Greeting all:  
ansible likes to ignore lines from my inventory based on the host and not the full line, for example

host1 var1=a var2=b var3=c  
host1 var1=d var2=e var3=f

will only use “host1 var1=d var2=e var3=f”.  
Is there a way to stop this and not have to split out the “duplicates” into multiple inventory files.  
thx  
lost\_in\_ansible

---

<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:** [February 3, 2025, 7:01pm UTC](https://forum.ansible.com/t/ansible-ignores-line-from-my-inventory-file/40022/2 "2025-02-03T19:01:58Z")

</div>

it is not ignoring the line, it is just merging them since you define `host1` twice and `inventory_hostname` is a unique identifier, so any conflicting variables will be updated to the value last defined. Try adding `var4` only to the first line and `var5` only to the 2nd, you’ll see that they both exist and have the expected value.

Also splitting into multiple files will do nothing as the inventory is merged from all sources before execution starts.

---

<div class="post-metadata">

**Author:** ![lost\_in\_ansible](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@lost\_in\_ansible](https://forum.ansible.com/u/lost_in_ansible)\
**Post date:** [February 3, 2025, 7:24pm UTC](https://forum.ansible.com/t/ansible-ignores-line-from-my-inventory-file/40022/3 "2025-02-03T19:24:39Z")

</div>

thank you for this, makes sense, but did not work, it took the last values again. this reply does explain how its working tho…  
I guess i’ll have to “awk” it out to unique files  
thanks again for your help and patience  
lia

---

<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:** [February 3, 2025, 7:26pm UTC](https://forum.ansible.com/t/ansible-ignores-line-from-my-inventory-file/40022/4 "2025-02-03T19:26:13Z")

</div>

please show a full example with `ansible-inventory`, what you state is not what i can reproduce.

hosts.ini

```ini
host1 var1=a var2=b var3=c var4=d
host1 var1=d var2=e var3=f var5=d

```

When I run `ansible-inventory -i hosts.ini --list`:

```json
{
    "_meta": {
        "hostvars": {
            "host1": {
                "var1": "d",
                "var2": "e",
                "var3": "f",
                "var4": "d",
                "var5": "d"
            }
        }
    },
    "all": {
        "children": [
            "ungrouped"
        ]
    },
    "ungrouped": {
        "hosts": [
            "host1"
        ]
    }
}

```

clearly shows the duplicate and non duplicate vars

---

<div class="post-metadata">

**Author:** ![lost\_in\_ansible](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@lost\_in\_ansible](https://forum.ansible.com/u/lost_in_ansible)\
**Post date:** [February 3, 2025, 7:48pm UTC](https://forum.ansible.com/t/ansible-ignores-line-from-my-inventory-file/40022/5 "2025-02-03T19:48:11Z")

</div>

this is a secure system , i can’t show more than what I have disclosed, but when I execute the above statement , yes I get similar output.  
what i can tell you is that the those “two” lines ( I actually have upto 12 changes going to 30 different servers ) make database call to change two different parameters (positional parameters) and only the last is being performed.  
anything else, you want me to try, please advise.  
thanks  
LIA

---

<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:** [February 3, 2025, 8:19pm UTC](https://forum.ansible.com/t/ansible-ignores-line-from-my-inventory-file/40022/6 "2025-02-03T20:19:23Z")

</div>

You do not need to show your confidential data, but you should show a full reproducer of the issue, as of now I cannot grasp what the real issue is as my example proves it works as I said, but you give me no example of the contrary.

---

<div class="post-metadata">

**Author:** ![lost\_in\_ansible](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@lost\_in\_ansible](https://forum.ansible.com/u/lost_in_ansible)\
**Post date:** [February 3, 2025, 8:43pm UTC](https://forum.ansible.com/t/ansible-ignores-line-from-my-inventory-file/40022/7 "2025-02-03T20:43:18Z")

</div>

Ok, so my final solution for this was to write a shell script that sorts the inventory file, break is into unique [groups], then create a template yml file to be "SED"ed by the number of groups and create a new yml file that is repeated n times (groups) so:  
inventory file:  
[group1]  
x  
x  
[group2]  
x  
x  
[groupn]  
x  
and the yml file:  
— (three dashes)

- hosts group1( dash )  
code a
- hosts group2 ( dash )  
code a
- hosts groupn ( dash )  
code a

yes, its very kludggy, but it works as needed  
thanks again Brian for the explanation, on what was happening,  
I realize that this probably not how its suppose to work/be used…  
LIA
