uncomment line in file

184 views
Skip to first unread message

hoize

unread,
Jun 25, 2015, 2:09:29 AM6/25/15
to puppet...@googlegroups.com
Hello!

I want to uncomment a line in a file, for example:

/root/.bashrc
# export LS_OPTIONS='--color=auto'


after change:
export LS_OPTIONS='--color=auto'

After some searching for a solution, I found the Augeas-Tool and then the Augeas-Shellvar-Provider.
So I tried it:

  shellvar { "export LS_OPTIONS":
    ensure  =>  present,
    target  =>  "/root/.bashrc",
    uncomment =>  true,
  }

But I always get this error, regardless how I paraphrase the ressource "shellvar".

An alternative solution would be great, too. But with the file_line ressource, I can't imagine, that there is an very short and easy way.

I hope someone can help me! 

Thank You!

Hoize

Garrett Honeycutt

unread,
Jun 25, 2015, 3:08:44 AM6/25/15
to puppet...@googlegroups.com
On 6/25/15 2:09 AM, hoize wrote:
> Hello!
>
> I want to uncomment a line in a file, for example:
>
> _/root/.bashrc_
> # export LS_OPTIONS='--color=auto'
>
>
> _after change:_
> export LS_OPTIONS='--color=auto'
>
> After some searching for a solution, I found the Augeas-Tool and then
> the Augeas-Shellvar-Provider.
> So I tried it:
>
> shellvar { "export LS_OPTIONS":
> ensure => present,
> target => "/root/.bashrc",
> uncomment => true,
> }
>
> But I always get this error, regardless how I paraphrase the ressource
> "shellvar".
>
> An alternative solution would be great, too. But with the file_line
> ressource, I can't imagine, that there is an very short and easy way.
>
> I hope someone can help me!
>
> Thank You!
>
> Hoize

Hi Hoize,

Since we're talking about a comment, does it really matter if it is
still in the file? Bash certainly does not think so. The file_line()
function should work well for you if you want to manage individual lines
as opposed to the entire file. I would recommend this approach for its
simplicity instead of Augeas.

Best regards,
-g

--
Garrett Honeycutt
@learnpuppet
Puppet Training with LearnPuppet.com
Mobile: +1.206.414.8658

hoize

unread,
Jun 25, 2015, 3:11:34 AM6/25/15
to puppet...@googlegroups.com
Hi Garrett,

do you mean to add the lines again, with file_line? I thought about this option, too. 

It would be a great way to uncomment this lines, but if it is easier with file_line, I will do it so.

Francois Lafont

unread,
Jun 25, 2015, 6:21:46 AM6/25/15
to puppet...@googlegroups.com
Hi,

On 25/06/2015 08:09, hoize wrote:

> I want to uncomment a line in a file, for example:
>
> */root/.bashrc*
> # export LS_OPTIONS='--color=auto'
>
>
> *after change:*
> export LS_OPTIONS='--color=auto'

Maybe this (not tested):


file_line { 'uncomment-line-in-bashrc':
path => '/root/.bashrc',
line => "export LS_OPTIONS='--color=auto' # Uncommented by Puppet",
match => '^#?[[:space:]]*export LS_OPTIONS=.*$',
}


file_line is provided by the stdlib (which should be installed of course).
HTH.


François Lafont
Reply all
Reply to author
Forward
0 new messages