jto
jto

Reputation: 185

How to replace a commented line in sudoers file with sed via Salt Stack?

Hi I would like to change the following line in the /etc/sudoers file on all of my Salt minions.

# %wheel        ALL=(ALL)       NOPASSWD: ALL

With the following:

%wheel          ALL=(ALL)       NOPASSWD: /usr/bin/salt*

So far I have tried the following command along with a plethora of similar commands with slightly different options/syntax:

sed -i '/# %wheel        ALL=(ALL)       NOPASSWD: ALL/c %wheel          ALL=(ALL)       NOPASSWD: /usr/bin/salt*' /etc/sudoers

I don't get an error message from this particular command, however file is not updated.

Could anyone provide me with the correct option/syntax for my specific use?

Upvotes: 0

Views: 1810

Answers (3)

jto
jto

Reputation: 185

For those wondering how to run this command against all minions via Salt (using @CWLiu's answer) you must add the following:

salt -C 'G@roles:apiserver' cmd.run 'sed -i '"'"'s|# \(.*\)ALL|\1/usr/bin/salt*|'"'"' /etc/sudoers'

To comply with Salt Stack's cmd.run syntax

Upvotes: 0

RomanPerekhrest
RomanPerekhrest

Reputation: 92854

Use the following sed expression:

sed 's~^# *\(%wheel *ALL=(ALL) *.*\)ALL~\1/usr/bin/salt*~' /etc/sudoers

Upvotes: 0

CWLiu
CWLiu

Reputation: 4043

$ sed -i 's|# \(.*\)ALL|\1/usr/bin/salt*|' /etc/sudoers

Upvotes: 2

Related Questions