>
>  replace { 'dummy5':
>>
>
> Er... I didn't even know a "replace" resource type existed. Where does it 
> come from?
>

I got it from

http://projects.puppetlabs.com/projects/1/wiki/simple_text_patterns

which now is dead, but can be read at

https://web.archive.org/web/20130318200928/http://projects.puppetlabs.com/projects/1/wiki/simple_text_patterns

I created manifests/classes/replace.pp and put in

# Replace a perl regexp with a string:
define replace($file, $pattern, $replacement) {
    $pattern_no_slashes = slash_escape($pattern)
    $replacement_no_slashes = slash_escape($replacement)

    exec { "/usr/bin/perl -pi -e 
's/$pattern_no_slashes/$replacement_no_slashes/' '$file'":
        onlyif => "/usr/bin/perl -ne 'BEGIN { \$ret = 1; } \$ret = 0 if 
/$pattern_no_slashes/ && ! /$replacement_no_slashes/ ; END { exit \$ret; }' 
'$file'",
    }
}


> There's no easy way to rename a file AFAIK.
> You can use something like this but it's far from ideal (and OS dependent 
> of course):
>
>   exec { '/bin/mv /etc/xdg/user-dirs.conf /etc/xdg/user-dirs.conf_false':
>
>     creates => '/etc/xdg/user-dirs.conf_false',
>
>   }
>
>   ->
>
>   file { '/etc/xdg/user-dirs.conf':
>
>     ensure => absent,
>
>   }
>

Very interesting use of "->". Thanks =)
 

> Regarding modifying content, you can have a look at the augeas resource 
> type. You need to have Augeas installed on the machine, but if the files to 
> be modified have some standard format then you might be lucky because you 
> can do your edits without much effort.
>
> Some useful links:
> http://docs.puppetlabs.com/references/3.stable/type.html#augeas
> http://docs.puppetlabs.com/guides/augeas.html
> http://doauto.wordpress.com/2013/06/22/how-to-change-a-file-using-puppet/
>
>
This is great! Much better solution!! Thanks =)



 

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/86a661f6-75e6-4e13-a9a0-50be8bf61c89%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to