Reputation: 1069
Background:
I'd like to comment out the following line in /etc/fstab
:
/dev/mapper/rhel-swap swap swap defaults 0 0
After reading the Salt documentation on salt.states.file.comment, I came up with this in my .sls
:
Permanently Disable Swap Memory:
file.comment:
- name: /etc/fstab
- regex: swap
(I also tried ^swap
.)
The output:
ID: Permanently Disable Swap Memory on Cassandra Nodes
Function: file.comment
Name: /etc/fstab
Result: True
Comment: Commented lines successfully
Started: 08:13:09.809454
Duration: 25.587 ms
Changes:
----------
/etc/fstab:
updated
The result: The line still isn't commented out. Notice the last line in my /etc/fstab
after the Salt install:
/dev/mapper/rhel-root / xfs defaults 0 0
UUID=69cb98f5-5325-4168-a28c-c1219081ae16 /boot xfs defaults 0 0
/dev/mapper/rhel-home /home xfs defaults 0 0
/dev/mapper/rhel-swap swap swap defaults 0 0
~
Questions:
Why wouldn't this line be commented out, despite the successful output from Salt?
The documentation says I need to include the leading ^
anchor, but doesn't that match the beginning of the line? How would I get a regex working that uses ^
and also matches the word swap
, which occurs in the middle of the line?
Other info:
Upvotes: 0
Views: 1680
Reputation: 1069
Not sure why it wasn't working originally, but here's the regex that worked: ^(\/).*swap.*$
. This matches any line starting with /
and containing the word swap
.
Here's the full salt step:
Permanently Disable Swap Memory:
file.comment:
- name: /etc/fstab
- regex: ^(\/).*swap.*$
Upvotes: 2