Ask Your Question
0

how to manipulate value in array with augeas?

asked 2015-07-10 06:47:30 -0500

buzzdeee gravatar image

Hi,

I want to use the kmod module on SLES, but it doesn't support SLES yet. I've seen, for Debian, its using augeas, so I thought I use augeas too (It's my first time looking into it).

What I have to do is to edit the /etc/sysconfig/kernel file, which has a line:

MODULESLOADEDON_BOOT="test blah blubb"

And what I want to do is to add specific modules as needed to that line, i.e. the fuse module: MODULESLOADEDON_BOOT="test blah blubb fuse"

running augtool manually, it works as expected:

testvm:~ # augtool 
augtool> ls /files/etc/sysconfig/kernel/MODULES_LOADED_ON_BOOT/
quote = "
value[1] = test
value[2] = blah
value[3] = blubb
augtool> set /files/etc/sysconfig/kernel/MODULES_LOADED_ON_BOOT/value[last()+1] fuse
augtool> ls /files/etc/sysconfig/kernel/MODULES_LOADED_ON_BOOT/
quote = "
value[1] = test
value[2] = blah
value[3] = blubb
value[4] = fuse
augtool> save
Saved 1 file(s)
augtool>
testvm:~ # grep MODULES_LOADED_ON_BOOT /etc/sysconfig/kernel 
MODULES_LOADED_ON_BOOT="test blah blubb fuse"

however, now trying the same via Puppet I get:

==> default: Debug: Augeas[shell_config_fuse](provider=augeas): Opening augeas with root /, lens path , flags 64
==> default: Debug: Augeas[shell_config_fuse](provider=augeas): Augeas version 1.3.0 is installed
==> default: Debug: Augeas[shell_config_fuse](provider=augeas): Will attempt to save and only run if files changed
==> default: Debug: Augeas[shell_config_fuse](provider=augeas): sending command 'set' with params ["/files/etc/sysconfig/kernel/MODULES_LOADED_ON_BOOT/value[last()+1]", "fuse"]
==> default: Debug: Augeas[shell_config_fuse](provider=augeas): Put failed on one or more files, output from /augeas//error:
==> default: Debug: Augeas[shell_config_fuse](provider=augeas): /augeas/files/etc/sysconfig/kernel/error = put_failed
==> default: Debug: Augeas[shell_config_fuse](provider=augeas): /augeas/files/etc/sysconfig/kernel/error/path = /files/etc/sysconfig/kernel/MODULES_LOADED_ON_BOOT
==> default: Debug: Augeas[shell_config_fuse](provider=augeas): /augeas/files/etc/sysconfig/kernel/error/lens = /usr/share/augeas/lenses/dist/shellvars.aug:162.8-.29:
==> default: 
==> default: Debug: Augeas[shell_config_fuse](provider=augeas): /augeas/files/etc/sysconfig/kernel/error/message = Failed to match 
==> default:     { /export/ }?(() | { /[0123456789]+/ = /(([^\001-\004\t\n "'-);`]|\\\\")+|("([^\001-\004"\\]|\\\\[^\001-\004\n]|[\t ]*\\\\\n[\t ]*)*"|'[^\001-\004']*')+|`[^\001-\004\n`]*`|``[^\001-\004\t\n ;`]+``|\\$\\([^\001-\004\n#\\]*\\)|\\$\\(\\([^\001-\004\n#)\\]*\\)\\))/ }{ /[0123456789]+/ = /(([^\001-\004\t\n "'-);`]|\\\\")+|("([^\001-\004"\\]|\\\\[^\001-\004\n]|[\t ]*\\\\\n[\t ]*)*"|'[^\001-\004']*')+|`[^\001-\004\n`]*`|``[^\001-\004\t\n ;`]+``|\\$\\([^\001-\004\n#\\]*\\)|\\$\\(\\([^\001-\004\n#)\\]*\\)\\))/ }*)({ /#comment/ = /[^\001-\004\t\n\r ][^\001-\004\n]*[^\001-\004\t\n\r ]|[^\001-\004\t\n\r ]/ } | ())
==> default:   with tree
==> default:     { "value" = "fuse" }
==> default: Debug: Augeas[shell_config_fuse](provider=augeas): Closed the augeas connection

I've forked the module, and my changes are here: https://github.com/buzzdeee/puppet-km... the important stuff is, that I first define the changes to be done:

  $changes = "set MODULES_LOADED_ON_BOOT/value[last()+1] '${name}'"

  and here is the augeas resource I use
  augeas { "shell_config_$name":
    lens    => 'Shellvars.lns',
    incl    => $kernelfile,
    force  => false,
    changes => $changes,
    #onlyif  => $onlyif,
  }

I initially tried without the force parameter, and also with force => true, but with force => true I get an even werirdo error, and I ... (more)

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2015-07-11 14:25:14 -0500

domcleal gravatar image

updated 2015-07-11 14:40:58 -0500

The augtool example is using a different lens to your Puppet resource, so the behaviour's different. The default lens to load /etc/sysconfig/kernel is Shellvars_list.lns, so try changing the lens parameter of the augeas resource to use that instead.

When using augtool, you can run print /augeas/files/etc/sysconfig/kernel to see the metadata about the file (note the /augeas prefix) which includes the lens used to parse it.

The different between Shellvars and Shellvars_list is precisely for files and variables like in this example. Shellvars would simply represent the value of MODULESLOADEDON_BOOT as one long string (which it would be in shell), but Shellvars_list splits up strings into multiple values based on whitespace. In this instance, where you're adding a single value to whatever's there, this is what you need.

I should note that there's also a Puppet module specifically for these kind of edits to shell files, augeasproviders_shellvar. The appending to arrays section of its README shows a very similar example.

edit flag offensive delete link more
0

answered 2015-07-13 03:47:22 -0500

buzzdeee gravatar image

Thanks a lot,

using Shellvar_list.lns did the trick. I know it must have been something that simple I got wrong ;)

Also thanks for the pointer to the augeasproviders_shellvars module, since the kmod module is not mine, I didn't wanted to make it depend on another module at a first try, but I'll keep it in mind for my own stuff.

cheers, Sebastian

edit flag offensive delete link more

Comments

Glad it worked. If you press the tick on the left next to my answer, it'll mark it as correct.

domcleal gravatar imagedomcleal ( 2015-07-13 07:40:36 -0500 )edit

Ah, I was looking for something like that already, done!

buzzdeee gravatar imagebuzzdeee ( 2015-07-13 08:46:58 -0500 )edit

Your Answer

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

Add Answer

Question Tools

2 followers

Stats

Asked: 2015-07-10 06:47:30 -0500

Seen: 718 times

Last updated: Jul 13 '15