how to use lineinfile to add block of <Location /test> .... </Location>

Hi,

I tried to insert flowing block, but the last was never inserted because that line has already existed for other block in the config file. How can I make it work?

  • name: “add test block”
    lineinfile: insertafter=“{{ item.after }}” line=“{{ item.line }}” dest=/etc/apache2/sites-available/default-ssl.conf state=present
    with_items:
  • { after: ‘EOF’, line: ‘<Location /test>’ }
  • { after: ‘^<Location /test>’, line: ‘ProxyPass ajp://localhost:9000/api’ }
  • { after: ‘^ProxyPass ajp://localhost:9000/api’, line: ‘’ }
    sudo: true

Thank you.

  • j