I had to modify your task in order to make it compile.
- name: add {{ extra_path }} to path ansible.builtin.lineinfile: dest: /etc/environment state: present backrefs: yes regexp: 'PATH=(["]*)((?!.*?{{ extra_path }}).*?)(["]*)$' line: 'PATH=\1\2:{{ extra_path }}\3'
My ansible version: ansible 2.9.21 config file = /etc/ansible/ansible.cfg configured module search path = [u'/home/vagrant/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python2.7/dist-packages/ansible executable location = /usr/bin/ansible python version = 2.7.16 (default, Oct 10 2019, 22:02:15) [GCC 8.3.0]
ansible 2.9.21 config file = /etc/ansible/ansible.cfg configured module search path = [u'/home/vagrant/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python2.7/dist-packages/ansible executable location = /usr/bin/ansible python version = 2.7.16 (default, Oct 10 2019, 22:02:15) [GCC 8.3.0]
I had to modify your task in order to make it compile.
My ansible version:
ansible 2.9.21 config file = /etc/ansible/ansible.cfg configured module search path = [u'/home/vagrant/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python2.7/dist-packages/ansible executable location = /usr/bin/ansible python version = 2.7.16 (default, Oct 10 2019, 22:02:15) [GCC 8.3.0]