Bug #5979
closedDocument usage of line replacement in Enforce a file content technique
Description
Situation:
In file /etc/sysctl.conf:
node 1 has: kernel.shmmax = 1234
node 2 has: kernel.shmmax = 4321
node 3 has: kernel.shmmax = 2143
Actually the value could be anything. And I don't (want to) know what is is.
Now I want to accomplish this:
node 1 has: kernel.shmmax = 5678
node 2 has: kernel.shmmax = 5678
node 3 has: kernel.shmmax = 5678
What I need here is one simple regex that matches:
All lines in sysctl.conf, which start with "kernel.shmmax", followed by a space, followed by an = sign, followed by a space, followed by a number I don't know.
Please provide documentation on how to do this.
Updated by Nicolas CHARLES almost 10 years ago
Hi Dennis,
To do that, you need to use the technique enforce a file content, with parameters
Path or file name: /etc/sysctl.conf
Enable the replacement of lines using a regexp: True
Regular expression kernel.shmmax = (?!5678$).*
String used as a remplacement kernel.shmmax = 5678
Note: we are eagerly backslashing backslashes, so \s get replaced by \\s, breaking the regexp, and causing your issue. Sorry about that, i'm opening a ticket for this
Updated by Dennis Cabooter almost 10 years ago
Problem solved. Maybe i would be nice to document the way regexes are working within techniques. This (?!5678$).* I really didn't know.
Updated by Nicolas CHARLES over 9 years ago
- Category set to Techniques
- Assignee set to Nicolas CHARLES
- Target version set to 2.10.13
Updated by Nicolas CHARLES over 9 years ago
- Status changed from New to Pending technical review
- Assignee changed from Nicolas CHARLES to Benoît PECCATTE
- Pull Request set to https://github.com/Normation/rudder-techniques/pull/647
Updated by Nicolas CHARLES over 9 years ago
- Related to deleted (Bug #6431: How to line replacement in Enforce a file content )
Updated by Nicolas CHARLES over 9 years ago
- Has duplicate Bug #6431: How to line replacement in Enforce a file content added
Updated by Nicolas CHARLES over 9 years ago
- Status changed from Pending technical review to Pending release
- % Done changed from 0 to 100
Applied in changeset rudder-techniques|a72a40bd2ecfca5b78820bb43f06a521476feb9c.
Updated by Benoît PECCATTE over 9 years ago
Applied in changeset rudder-techniques|704cd3cf0362b9b434a1d04429c4fa3c41b479e4.
Updated by Vincent MEMBRÉ over 9 years ago
- Subject changed from Please document usage of line replacement in Enforce a file content technique to Document usage of line replacement in Enforce a file content technique
Updated by Vincent MEMBRÉ over 9 years ago
- Status changed from Pending release to Released