Ask Your Question
0

same user insert issue one after the other with augeas

asked 2015-03-25 11:49:31 -0500

Chutki gravatar image

updated 2015-03-25 11:51:20 -0500

Hi,

I have requirement for suders file to add "suuser" user

tried with augeas resource

"set spec[user = 'suuser01']/user suuser01",
"set spec[user = 'suuser01']/host_group/host ALL",
"set spec[user = 'suuser01']/host_group/command '/usr/bin/du'",
"set spec[user = 'suuser01']/host_group/command/runas_user root",
"set spec[user = 'suuser01']/host_group/command/tag NOPASSWD",
"set spec[user = 'suuser01']/user suuser01",
"set spec[user = 'suuser01']/host_group/host ALL",
"set spec[user = 'suuser01']/host_group/command '/opt/dir1'",
"set spec[user = 'suuser01']/host_group/command/runas_user root",
"set spec[user = 'suuser01']/host_group/command/tag NOPASSWD",
"set spec[user = 'suuser01']/user suuser01",
"set spec[user = 'suuser01']/host_group/host ALL",
"set spec[user = 'suuser01']/host_group/command '/opt/dir1'",
"set spec[user = 'suuser01']/host_group/command/runas_user root",
"set spec[user = 'suuser01']/host_group/command/tag NOPASSWD",

But I am not getting o/p like below

#HPUX/AIX/Linux
suuser01 ALL = (root) NOPASSWD: /usr/bin/du
suuser01 ALL = (root) NOPASSWD: /opt/dir1
suuser01 ALL = (root) NOPASSWD: /opt/dir2

My sudoers file o/p

suuser01 ALL = (root) NOPASSWD: /opt/dir2

I tried "ins with after" option but I am getting an error

option1:
"set spec[user = 'suuser01']/user suuser01",
"set spec[user = 'suuser01']/host_group/host ALL",
"set spec[user = 'suuser01']/host_group/command '/usr/bin/du'",
"set spec[user = 'suuser01']/host_group/command/runas_user root",
"set spec[user = 'suuser01']/host_group/command/tag NOPASSWD",
"ins  user after user[last()]",
"set user[last()] oyuser01",
"set spec[user = 'suuser01']/user suuser01",
"set spec[user = 'suuser01']/host_group/host ALL",
"set spec[user = 'suuser01']/host_group/command '/opt/dir1'",
"set spec[user = 'suuser01']/host_group/command/runas

option2 :
"set spec[user = 'suuser01']/user suuser01",
"set spec[user = 'suuser01']/host_group/host ALL",
"set spec[user = 'suuser01']/host_group/command '/usr/bin/du'",
"set spec[user = 'suuser01']/host_group/command/runas_user root",
"set spec[user = 'suuser01']/host_group/command/tag NOPASSWD",
"ins  spec after spec[last()]",
"set user[last()] oyuser01",
"set spec[user = 'suuser01']/user suuser01",
"set spec[user = 'suuser01']/host_group/host ALL",
"set spec[user = 'suuser01']/host_group/command '/opt/dir1'",
"set spec[user = 'suuser01']/host_group/command/runas

error

Error sending command 'ins' with params ["spec", "after", "/files/etc/sudoers/spec[last()"]
    /Error sending command 'ins' with params ["spec", "after", "/files/etc/sudoers/spec[last()"]

How I can insert "suuser01" one after the other.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-04-01 11:59:47 -0500

GregLarkin gravatar image

I find it very useful to start with the file in the desired final state, then fire up augtool to see how Augeas represents the desired changes internally. Then it's a question of working backwards to figure out the Augeas commands needed to build the file correctly.

Using that procedure, I figured out that the first command you need to add the desired line is:

set spec[user = 'suuser01'][command = '/usr/bin/du']/user 'suuser01'

Once you do that, you can continue with other commands like this one until you build up the entire line:

set spec[last()]/host_group

Hope that helps.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2015-03-25 11:49:31 -0500

Seen: 190 times

Last updated: Apr 01 '15