puppet+augeas modprobe.conf

549 views
Skip to first unread message

lance dillon

unread,
Jun 9, 2009, 10:43:07 AM6/9/09
to puppet...@googlegroups.com
I need to be able to add:

alias usb-storage off

to /etc/modprobe.conf

I have this so far:

  augeas { "usb-storage":
    context => "/files/etc/modprobe.conf",
    changes => [ "set alias[last()+1] usb-storage",
                 "set alias[last()]/modulename off",
               ],
    onlyif => "get alias != usb-storage"
  }


The change works, but the onlyif part does not.

augtool> print /files/etc/modprobe.conf/alias[*]
/files/etc/modprobe.conf/alias[1] = "eth0"
/files/etc/modprobe.conf/alias[1]/modulename = "vmnics"
/files/etc/modprobe.conf/alias[2] = "scsi_hostadapter"
/files/etc/modprobe.conf/alias[2]/modulename = "mptbase"
/files/etc/modprobe.conf/alias[3] = "scsi_hostadapter1"
/files/etc/modprobe.conf/alias[3]/modulename = "mptscsih"
/files/etc/modprobe.conf/alias[4] = "char-major-14"


I need to be able to detect if usb-storage already exists as a module name, so I don't add the alias line multiple times.  I've tried several things, but none of them seem to do what I want.

Does anybody have any ideas?  I'm still experimenting, and if I find an answer, I'll post it.

Thanks

/lsd

Bryan Kearney

unread,
Jun 9, 2009, 11:16:59 AM6/9/09
to puppet...@googlegroups.com
lance dillon wrote:
> I need to be able to add:
>
> alias usb-storage off
>
> to /etc/modprobe.conf
>
> I have this so far:
>
> augeas { "usb-storage":
> context => "/files/etc/modprobe.conf",
> changes => [ "set alias[last()+1] usb-storage",
> "set alias[last()]/modulename off",
> ],
> onlyif => "get alias != usb-storage"
> }


try onlyif => "match alias include usb-storage"

it may be

"match alias[*] include usb-storage"

-- bk


lance dillon

unread,
Jun 9, 2009, 11:50:16 AM6/9/09
to puppet...@googlegroups.com
Hmm, that didn't quite do it either.  Now it doesn't run regardless.  It is supposed to add that line if usb-storage doesn't exist, and ignore if it does (I don't want to add it multiple times).  The logic above seems to be the opposite, but either way, nothing happened.

Thanks for the info though.  Now I have another command to check with (using include).

Bryan Kearney

unread,
Jun 9, 2009, 11:57:15 AM6/9/09
to puppet...@googlegroups.com

Ok.. lets try this (lutter knows this voodoo better)

"match *[alias ='usb-storage'] size = 0 "

-- bk

lance dillon

unread,
Jun 9, 2009, 12:18:45 PM6/9/09
to puppet...@googlegroups.com
Seems closer, but not quite.

 augtool> match /files/etc/modprobe.conf/alias[*]
/files/etc/modprobe.conf/alias[1] = eth0
/files/etc/modprobe.conf/alias[2] = scsi_hostadapter
/files/etc/modprobe.conf/alias[3] = scsi_hostadapter1
/files/etc/modprobe.conf/alias[4] = char-major-14
/files/etc/modprobe.conf/alias[5] = usb-storage
augtool> match /files/etc/modprobe.conf/alias[*='usb-storage']
  (no matches)
augtool> match /files/etc/modprobe.conf/alias[='usb-storage']
  (error matching /files/etc/modprobe.conf/alias[='usb-storage'])
augtool> match /files/etc/modprobe.conf/alias[*='usb-storage']
  (no matches)
augtool> match /files/etc/modprobe.conf/alias[*="usb-storage"]
  (no matches)

This may give more information.

thanks


Bryan Kearney

unread,
Jun 9, 2009, 1:02:13 PM6/9/09
to puppet...@googlegroups.com


ok.. I think this is it in augtool:

match /files/etc/modprobe.conf/*[.="foo"]

so.. in the plugin you can do

'match /files/etc/modprobe.conf/*[.="foo"] size = 0'

-- bk


Bryan Kearney

unread,
Jun 9, 2009, 1:09:00 PM6/9/09
to puppet...@googlegroups.com
Bryan Kearney wrote:
>> thanks
>
>
> ok.. I think this is it in augtool:
>
> match /files/etc/modprobe.conf/*[.="foo"]
>
> so.. in the plugin you can do
>
> 'match /files/etc/modprobe.conf/*[.="foo"] size = 0'
>

more specific matching:

match /files/etc/modprobe.conf/alias[.="foo"]

lance dillon

unread,
Jun 9, 2009, 2:19:13 PM6/9/09
to puppet...@googlegroups.com
The problem with modprobe.conf is that it is more like:

command args

than

key value


key value usually has unique keys, but command args doesn't.

It's kind of weird  A lot of those commands work on something else, say /etc/hosts, or /etc/fstab, something that is key value, but just not working on /etc/modprobe.conf.

 

Bryan Kearney

unread,
Jun 9, 2009, 2:21:39 PM6/9/09
to puppet...@googlegroups.com


Can you please send me your target modprobe.conf file?

-- bk

lance dillon

unread,
Jun 9, 2009, 3:30:36 PM6/9/09
to puppet...@googlegroups.com

> The problem with modprobe.conf is that it is more like:
>
> command args
>
> than
>
> key value
>
>
> key value usually has unique keys, but command args doesn't.
>
> It's kind of weird  A lot of those commands work on something else, say
> /etc/hosts, or /etc/fstab, something that is key value, but just not working
> on /etc/modprobe.conf.


Can you please send me your target modprobe.conf file?

-- bk
 

alias eth0 vmnics
alias scsi_hostadapter mptbase
alias scsi_hostadapter1 mptscsih
install bond0 /sbin/modprobe bonding -o bond0 miimon=100 mode=1
# Added by VMware Tools
install pcnet32 /sbin/modprobe -q --ignore-install vmxnet;/sbin/modprobe -q --ignore-install pcnet32 $CMDLINE_OPTS;/bin/true
alias char-major-14 sb
options sb io=0x220 irq=5 dma=1 dma16=5 mpu_io=0x330
#alias usb-storage off


If alias usb-storage off isn't present, it should add it, otherwise do nothing.

Like I said, I'm still experimenting with options, but nothing has worked right yet.

David Lutterkort

unread,
Jun 9, 2009, 6:54:34 PM6/9/09
to puppet...@googlegroups.com
On Tue, 2009-06-09 at 11:57 -0400, Bryan Kearney wrote:
> Ok.. lets try this (lutter knows this voodoo better)

It's not voodoo, it's XPath ;)

> "match *[alias ='usb-storage'] size = 0 "

That almost works, though shouldn't that second '=' be '==' ? (and maybe
we should make the augeas provider use '=' there, too, for consistency)

I would write this as

augeas { "usb-storage":
context => "/files/etc/modprobe.conf",
changes => [ "set alias[last()+1] usb-storage",
"set alias[last()]/modulename off",
],

onlyif => "match alias[.='usb-storage'] size == 0'
}

The fact that the modprobe.conf format is 'command args' with differing
meanings of the args for the various commands doesn't matter too much -
it just leads to different tree structures for those commands. For
example for the command 'alias NAME MODULE' the tree structure is

alias = 'NAME'
modulename = 'MODULE'

IOW, the name of the alias becomes the value of the 'alias' node, and
the name of the module is put as the value of a node labelled
'modulename'.

David


lance dillon

unread,
Jun 10, 2009, 8:06:56 AM6/10/09
to puppet...@googlegroups.com
That doesn't quite work either:

### print /files/etc/modprobe.conf
...
 /files/etc/modprobe.conf/alias[5] = "usb-storage"
/files/etc/modprobe.conf/alias[5]/modulename = "off"

Bryan Kearney

unread,
Jun 10, 2009, 9:15:12 AM6/10/09
to puppet...@googlegroups.com
lance dillon wrote:
> O

>>
>> That doesn't quite work either:
>
> ### print /files/etc/modprobe.conf
> ...
> /files/etc/modprobe.conf/alias[5] = "usb-storage"
> /files/etc/modprobe.conf/alias[5]/modulename = "off"
> augtool> match /files/etc/modprobe.conf/alias[='usb-storage']
> (error matching /files/etc/modprobe.conf/alias[='usb-storage'])
> augtool>


I believe you need

/files/etc/modprobe.conf/alias[.='usb-storage']

lance dillon

unread,
Jun 10, 2009, 11:30:51 AM6/10/09
to puppet...@googlegroups.com

That did it.  Thanks for the help guys.  That was exactly what I needed.

-lsd

 

Reply all
Reply to author
Forward
0 new messages