why lineinfile not able to run with item.path

14 views
Skip to first unread message

Sameer Modak

unread,
May 1, 2023, 11:24:41 AM5/1/23
to Ansible Project
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}

Abhijeet Kasurde

unread,
May 1, 2023, 11:35:56 AM5/1/23
to ansible...@googlegroups.com
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.

--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f34a22cb-eaee-41b0-9573-5c09dc7b9517n%40googlegroups.com.


--
Thanks,
Abhijeet Kasurde

Rowe, Walter P. (Fed)

unread,
May 1, 2023, 12:20:53 PM5/1/23
to 'Rowe, Walter P. (Fed)' via Ansible Project
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
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

Rowe, Walter P. (Fed)

unread,
May 1, 2023, 12:20:53 PM5/1/23
to 'Rowe, Walter P. (Fed)' via Ansible Project
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
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123
On May 1, 2023, at 11:24 AM, Sameer Modak <sameer.m...@gmail.com> wrote:

Sameer Modak

unread,
May 1, 2023, 2:44:27 PM5/1/23
to Ansible Project
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.

Sameer Modak

unread,
May 1, 2023, 2:49:11 PM5/1/23
to Ansible Project
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.

sumanth parakala

unread,
May 1, 2023, 2:56:42 PM5/1/23
to ansible...@googlegroups.com
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.



Abhijeet Kasurde

unread,
May 1, 2023, 2:58:02 PM5/1/23
to ansible...@googlegroups.com
Please feel free to improve the error reporting if you feel it is necessary. :)



--
Thanks,
Abhijeet Kasurde

sumanth parakala

unread,
May 1, 2023, 3:02:47 PM5/1/23
to ansible...@googlegroups.com
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..

Abhijeet Kasurde

unread,
May 1, 2023, 3:04:30 PM5/1/23
to ansible...@googlegroups.com
It is always upto us.



--
Thanks,
Abhijeet Kasurde
Reply all
Reply to author
Forward
0 new messages