I'm looking for a reasonable way to insert a block of lines into a certain 
position within a file hopefully 'without' needing to template the 
destination file.

I have a config file that I need to insert multiple lines into.

[SectionA]
  ... many lines below here ...
[SectionB]
  ... many more lines below here...
[SectionC]
  ... and so on...


What I'm trying to do is insert a block of lines just above the 'SectionB' 
line.


[SectionA]
  ... many lines below here ... 

*  [[subsectionX]]*
*     HTML_ROOT = /path/here*
*  [[subsectionY]]*
*    HTML_ROOT = /path/here*

     [SectionB]
         ... many more lines below here...
     [SectionC]
       ... and so on...

I tried a 'with_items' approach ala:

- name: insert the lines
  lineinfile: dest=/config/file/path line="{{ item }}" 
insertbefore='[SectionB]'
  with_items:
  - " [[subsectionX]]"
  - "   HTML_ROOT = /path/here"
  - " [[subsectionY]]"
  - "   HTML_ROOT = /path/here"


This struck me as a bit of a kludge, and it failed anyway as ansible only 
adds the first 'HTML_ROOT =" line into the file, and does not add the 
second one (being a little too smart for its own good)

Is there a preferred way to do this kind of stuff ?





-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/8b5da77b-3d2f-45b9-a8b0-a6b4e9ebd2a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to