Hi everyone,
I have one play that does not do what I want it to:
- name: set kernel multiversions
lineinfile:
dest: /etc/zypp/zypp.conf
line: "multiversion.kernels = latest,oldest,running"
regexp: "multiversion.kernels = latest,latest-1,running"
state: present
I expect
-> the module scans for a line matching "regex"
-> if this is found, the found line is replaced with "line"
-> if "regex" has no matches, nothing is done
The module instead scans the file, and on the first run it behaves as I
expect, the line in the file is modified. On subsequent runs, one line
(per run) is added to the file (before EOF), so that I have multiple
lines containing "line".
Is this behaviour expected? How can I make a replacement only when
"regex" matches?
When using a registered variable, this variable is shown as:
ok: [hostname] => {
"myrole_var1": {
"backup": "",
"changed": true,
"diff": [
{
"after": "",
"after_header": "/etc/zypp/zypp.conf (content)",
"before": "",
"before_header": "/etc/zypp/zypp.conf (content)"
},
{
"after_header": "/etc/zypp/zypp.conf (file attributes)",
"before_header": "/etc/zypp/zypp.conf (file attributes)"
}
],
"msg": "line added"
}
}
So nothing I could use "when" on.
I use the blockinfile module to add a line in this file, but I do not
see how to use this module to replace one line. This module runs only
once, on subsequent runs it says "OK" instead of "Changed".
Regards,
Werner