I’m having a problem wrapping my head around something. There are other solutions out there that would solve my problem, but in the interest in learning to do something different I’m hoping someone can point out what I’m doing wrong with the lineinfile module.
I grep a file for a line with a specific line. The file line is “auth required pam_faillock.so preauth silent deny=3 unlock_time=604800 fail_interval=900” and I want to verify that it’s there exactly. If it is there but not exact, I want to change it. If it’s missing I want to add it it a specific spot. The only way I’ve been able to make it works is search and delete any line with the word “pam_faillock.so” in it and then run the module to add the line where it should be. What I have below works, but every time I run it, it changes the file even if the line is correct of obvious reasons. Any suggestions? Am I using the wrong module to complete this task? Thanks for the help.
Thanks very much Philippe for the post. That’s exactly what I’m trying to do. I’m still having an issue though with what you have below. If I change one of the variables, pam_fallock_unlock_time for example, it just adds another line instead of replacing the line. So I end up with two pam_faillock.so lines. I’m tinkering with it though. This gives me a good lead on what direction to look though. Thanks again!
Glad it helped a bit and thanks for pointing the current limitation, I will also see how to address it.
Generally we are leveraging the lineinfile module when working in remediation context where we want
to change one of the settings and not the whole file (in that later case the template module is better)
In that case this is more for original settings of the pam stack, and we do not generally change the values after.
So was good enough for us.
But making remediation generic enough can be hard, as shown by this case.
I need to learn more about how temples work because there are several things where it would be most useful. It’s a little confusing to me at the moment.
I wanted to just update this thread that when I shortened the regexp line in your example (like I have below), it worked exactly right every time and stopped duplicating. So thanks again.