Wild Card in Augeas

274 views
Skip to first unread message

Vikas Kumar

unread,
Aug 12, 2014, 1:28:26 AM8/12/14
to puppet...@googlegroups.com
Dear All,

I am trying to use augeas to change the value of NM_CONTROLLED to "no" on all my RHEL 6.X machines. However, the number of ethernet cards differ on each server, thus I want to use expression or wild cards.

      if $::operatingsystemmajrelease == '6' {
        augeas
{ "network-tweaks-RedHat":
        context
=> "/files/etc/sysconfig/network-scripts/ifcfg-eth[0-9]",
        changes
=> [
                   
'set /files/etc/sysconfig/network-scripts/ifcfg-eth[0-9]/NM_CONTROLLED \'"no"\'',
                   
],
       
}
     
}

I wrote the above code but it does't do the job. Please suggest.

Regards,
Vikas


David Lutterkort

unread,
Aug 13, 2014, 1:05:11 PM8/13/14
to puppet...@googlegroups.com
Hi Vikas,

to set multiple nodes, you need to use the 'setm' command; 'set' will only change a single node. Also, the path expressions in Augeas are more like XPath, and therefore don't have globbing built in. In augtool, you'd do what you want with this command:

   setm /files/etc/sysconfig/network-scripts/*[label() =~ glob('ifcfg-*')] NM_CONTROLLED no

The corresponding Augeas resource would be something like

augeas { "network-tweaks-RedHat":
        context => "/files/etc/sysconfig/network-scripts",
        changes
=> ["setm
*[label() =~ glob('ifcfg-*')] NM_CONTROLLED no"],
}

David

Vikas Kumar

unread,
Aug 14, 2014, 3:09:21 AM8/14/14
to puppet...@googlegroups.com
Hi David,

Many thanks for the information, but still I am having some issues with puppet class when I am trying to use double quotes.

This is working good
"setm *[label() =~ glob('ifcfg-eth*')] NM_CONTROLLED no",

But, this isn't. I tried few combinations of single and double quotes, but none of them are working :(
"setm *[label() =~ glob('ifcfg-eth*')] NM_CONTROLLED \'"no"\'",

Regards,
Vikas

David Lutterkort

unread,
Aug 14, 2014, 4:47:58 PM8/14/14
to puppet...@googlegroups.com
Hi Vikas,

On Thu, Aug 14, 2014 at 12:09 AM, Vikas Kumar <vika...@gmail.com> wrote:
 
But, this isn't. I tried few combinations of single and double quotes, but none of them are working :(
"setm *[label() =~ glob('ifcfg-eth*')] NM_CONTROLLED \'"no"\'",


The problem is that the Puppet string is enclosed in double quotes, and so the double quote before 'no' ends that string. If you want to quote the 'no' in the file you'll have to escape the double quotes (and there's no need to escape the single quotes):

"setm *[label() =~ glob('ifcfg-eth*')] NM_CONTROLLED '\"no\"'"

Though in this case, there's no need to quote the 'no'.

David

Vikas Kumar

unread,
Aug 14, 2014, 8:40:00 PM8/14/14
to puppet...@googlegroups.com
Awesome David, many thanks for the explanation and the code as well, works like a charm.

Regards,
Vikas
Reply all
Reply to author
Forward
0 new messages