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

-- 


-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/9c69765d-cdcb-30a4-0b17-76b143ccc2f6%40ufz.de.
For more options, visit https://groups.google.com/d/optout.

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to