I am trying to replace or append a path part to the path definition in /etc/environment on a linux box.
Here's what I have:
//all.yml
my_path: "/usr/bin:/usr/sbin"
my_extra_path: "/usr/extra/path"
In my role-file:
//updatePath.yml
- name: update /etc/environment
lineinfile:
dest=/etc/environment
state=present
backrefs=yes
regexp='PATH=({{ my_path }}:?)?({{ my_extra_path }}:?)?(.*)'
line='PATH={{ my_extra_path }}:{{ my_extra_path }}:\3'
Now when I run the role, it works fine updating an existing PATH-line, but not creating duplicates within the line or even duplicate lines. So far so good.
When there is no line with "PATH=" present, I would expect it to add a new one. But it doesn't.
Is my expectation wrong or where lies the problem?