lineinfile block missing last line

Hi,

Sorry for duplicating post here, I did not get any response from ansible-project.

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.

  • hce

Hi,

Consider using blockinfile module, which is exactly designed for such tasks.https://github.com/yaegashi/ansible-role-blockinfile

The module is available via blockinfile role in Ansible Galaxy so you can easily import it into your playbook.

https://galaxy.ansible.com/list#/roles/1475

`