# why lineinfile not able to run with item.path

**URL:** <https://forum.ansible.com/t/why-lineinfile-not-able-to-run-with-item-path/37944>\
**Category:** Ansible Project\
**Created:** [May 1, 2023, 3:24pm UTC](https://forum.ansible.com/t/why-lineinfile-not-able-to-run-with-item-path/37944 "2023-05-01T15:24:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sameer\_Modak](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sameer_modak/32/5180_2.png) [@Sameer\_Modak](https://forum.ansible.com/u/Sameer_Modak)\
**Post date:** [May 1, 2023, 3:24pm UTC](https://forum.ansible.com/t/why-lineinfile-not-able-to-run-with-item-path/37944/1 "2023-05-01T15:24:40Z")

</div>

Code==\>

- name: insert logggin file in log4j protperties

lineinfile:

path: ‘{{ item.path }}’

insertafter: ‘log4j.appender.kafkaAppender.layout.ConversionPattern=\*’

line: ‘{{ item.line }}’

with\_items:

- { path: ‘/etc/kafka/confluent-6.2.10/kafka/log4j.properties’, line: ‘log4j.appender.kafkaAppender.MaxFileSize=512MB’ }

- { path: ‘/etc/kafka/confluent-7.2.5/kafka/log4j.properties’, line: ‘log4j.appender.kafkaAppender.MaxFileSize=512MB’ }

- { path: ‘/etc/kafka/confluent-6.2.10/kafka/log4j.properties’, line: ‘log4j.appender.kafkaAppender.MaxBackupIndex=10’ }

- { path: ‘/etc/kafka/confluent-7.2.5/kafka/log4j.properties’, line: ‘log4j.appender.kafkaAppender.MaxBackupIndex=10’ }

ERROR==\>\>\>

item={‘path’: ‘/etc/kafka/confluent-7.2.5/zookeeper/log4j.properties’, ‘line’: ‘log4j.appender.kafkaAppender.MaxBackupIndex=10’}) =\> {“ansible\_loop\_var”: “item”, “changed”: false, “item”: {“line”: “log4j.appender.kafkaAppender.MaxBackupIndex=10”, “path”: “/etc/kafka/confluent-7.2.5/zookeeper/log4j.properties”}, “msg”: “Destination { item.path }} does not exist !”, “rc”: 257}

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [May 1, 2023, 3:35pm UTC](https://forum.ansible.com/t/why-lineinfile-not-able-to-run-with-item-path/37944/2 "2023-05-01T15:35:02Z")

</div>

It seems that you have a typo since the error message reads ‘_Destination { item.path }} does not exist !_’ which is missing a starting curling bracket.

Your playbook works fine though.

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [May 1, 2023, 4:20pm UTC](https://forum.ansible.com/t/why-lineinfile-not-able-to-run-with-item-path/37944/3 "2023-05-01T16:20:38Z")

</div>

You need proper indentation. The module name and “with\_items” must align with the task name. The module args would then outdent by two space to also reflect proper indentation. I used a “debug” vs “lineinfile” to display the item.path and item.line vars and it worked just fine once indentation was corrected.

- name: insert logggin file in log4j protperties  
lineinfile:  
path: ‘{{ item.path }}’  
insertafter: ‘log4j.appender.kafkaAppender.layout.ConversionPattern=\*’  
line: ‘{{ item.line }}’  
with\_items:
- { path: ‘/etc/kafka/confluent-6.2.10/kafka/log4j.properties’, line: ‘log4j.appender.kafkaAppender.MaxFileSize=512MB’ }
- { path: ‘/etc/kafka/confluent-7.2.5/kafka/log4j.properties’, line: ‘log4j.appender.kafkaAppender.MaxFileSize=512MB’ }
- { path: ‘/etc/kafka/confluent-6.2.10/kafka/log4j.properties’, line: ‘log4j.appender.kafkaAppender.MaxBackupIndex=10’ }
- { path: ‘/etc/kafka/confluent-7.2.5/kafka/log4j.properties’, line: ‘log4j.appender.kafkaAppender.MaxBackupIndex=10’ }

Walter

---

<div class="post-metadata">

**Author:** ![Sameer\_Modak](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sameer_modak/32/5180_2.png) [@Sameer\_Modak](https://forum.ansible.com/u/Sameer_Modak)\
**Post date:** [May 1, 2023, 6:44pm UTC](https://forum.ansible.com/t/why-lineinfile-not-able-to-run-with-item-path/37944/4 "2023-05-01T18:44:27Z")

</div>

Exaclty. The error is misleading as you can see my code its straightforward {{ before item.pah. Anyways i m trying what MR. Walter has suggested. Lets c. Thanks by the way for your response.

---

<div class="post-metadata">

**Author:** ![Sameer\_Modak](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sameer_modak/32/5180_2.png) [@Sameer\_Modak](https://forum.ansible.com/u/Sameer_Modak)\
**Post date:** [May 1, 2023, 6:49pm UTC](https://forum.ansible.com/t/why-lineinfile-not-able-to-run-with-item-path/37944/5 "2023-05-01T18:49:11Z")

</div>

Hello MR. Walter,

Thanks a lot. My code and understanding was fine but as you pointed out i somehow couldn’t see space in front. And as we know ansible is not good for error prompt i mislead it.

Thanks again. it worked by add 2 spaces in with\_items.

By the way any good tool or editor you can recommend which auto corrects or helps with this??

Also could you please tell me what did u do for troubleshooting is it only , debug or something else so that i ll try to do next time.

---

<div class="post-metadata">

**Author:** ![Sumanth\_Parakala](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sumanth\_Parakala](https://forum.ansible.com/u/Sumanth_Parakala)\
**Post date:** [May 1, 2023, 6:56pm UTC](https://forum.ansible.com/t/why-lineinfile-not-able-to-run-with-item-path/37944/6 "2023-05-01T18:56:14Z")

</div>

Documentation in various sites have a problem with with\_items , they all start the item list from the w of the with\_items , the indentation is almost incorrect in all majority of the knowledge sites for the list of items with variables.

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [May 1, 2023, 6:57pm UTC](https://forum.ansible.com/t/why-lineinfile-not-able-to-run-with-item-path/37944/7 "2023-05-01T18:57:27Z")

</div>

Please feel free to improve the error reporting if you feel it is necessary. 🙂

---

<div class="post-metadata">

**Author:** ![Sumanth\_Parakala](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sumanth\_Parakala](https://forum.ansible.com/u/Sumanth_Parakala)\
**Post date:** [May 1, 2023, 7:02pm UTC](https://forum.ansible.com/t/why-lineinfile-not-able-to-run-with-item-path/37944/8 "2023-05-01T19:02:20Z")

</div>

Except rol sites(that many don’t have access) I don’t think other sites that google hit take the indentation into account for the examples…it’s up to us…

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [May 1, 2023, 7:03pm UTC](https://forum.ansible.com/t/why-lineinfile-not-able-to-run-with-item-path/37944/9 "2023-05-01T19:03:55Z")

</div>

It is always upto us.
