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

18 views
Skip to first unread message

hce

unread,
Aug 17, 2015, 6:45:13 AM8/17/15
to Ansible Project
Hi,

I tried to insert flowing block, but the last </Location> 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: '</Location>' }
 sudo: true

Thank you.

- j

Reply all
Reply to author
Forward
0 new messages