error message from grep

18 views
Skip to first unread message

brad.v...@gmail.com

unread,
Jun 3, 2024, 10:14:30 AMJun 3
to Salt-users
We have a stanza:

{% if salt['cmd.run']('grep swap /etc/fstab') %}
swapoff_fstab:
  cmd.run:
    - name: sed -i.bak '/b\bswap\b/d' /etc/fstab
    - onlyif: grep -q '\bswap\b' /etc/fstab

every time it runs on a server where this has already successfully run, we get:

[ERROR   ] Command 'grep' failed with return code: 1
[ERROR   ] retcode: 1
[ERROR   ] Command 'grep' failed with return code: 1
[ERROR   ] output:

How do I restate it to get rid of the error messages?

James Pearson

unread,
Jun 4, 2024, 9:33:56 AMJun 4
to salt-...@googlegroups.com
Those messages are coming from the {% if salt['cmd.run']('grep swap
/etc/fstab') %} line

However, you don't need this check as you are also using 'onlyif' in
the stanza - which is also checking if that string appears in
/etc/fstab ?

It might be better to use something like 'file.line' to remove the
'swap' line - i.e. something like:

swapoff_fstab:
file.line:
- name: /etc/fstab
- match: '\bswap\b'
- mode: delete
- backup: True

It is also probably possible to use 'file.replace' to do something similar ?

James Pearson

brad.v...@gmail.com

unread,
Jun 4, 2024, 9:44:37 AMJun 4
to Salt-users
That makes sense.  Will give it a try.  That was one of my first attempts in salt.  So, not very "salty."  :)
Reply all
Reply to author
Forward
0 new messages