You'll want to create the file using file{} and then add require =>
File['/path/to/file'] so that the file is created before Puppet tries
to modify it.

You can do that with less typing by using the -> operator. For example:

  file { '/usr/share/X11/xorg.conf.d/glamor.conf':
    ensure => file,
    mode  => '0644',   # adjust as needed
    owner  => 'root',     # adjust as needed
    group  => 'root',    # adjust as needed
  }->
  file_line { 'hash_glamor':
    path  => '/usr/share/X11/xorg.conf.d/glamor.conf',
    line  => '#      Load  "glamoregl"',
    match => 'Load  "glamoregl"',
  }

Tom


On Mon, Jun 29, 2015 at 10:37 AM, Cam Mac <iuco...@gmail.com> wrote:
> Hi,
>
> I wanted to create a recipe for hashing a line in a file (I'd rather hash it
> than delete it), if the file is present and that particular line is present.
> I came up with a less than elegant solution and wondered whether
> someone knows of a better way.
>
> The file in question: /usr/share/X11/xorg.conf.d/glamor.conf
> The line in question (which needs to be commented):  Load  "glamoregl"
>
>   exec { 'hash_glamor':
>     path    => '/bin:/usr/sbin:/usr/bin',
>     command => 'sed -i \'s/\(^\s*Load\s*\"glamoregl\"$\)/\#\1/\'
> /usr/share/X11/xorg.conf.d/glamor.conf',
>     onlyif => 'grep -E "^\s*Load\s*\"glamoregl\"$"
> /usr/share/X11/xorg.conf.d/glamor.conf',
>   }
>
> I tried using the 'file_line' module:
>
>   file_line { 'hash_glamor':
>     path  => '/usr/share/X11/xorg.conf.d/glamor.conf',
>     line  => '#      Load  "glamoregl"',
>     match => 'Load  "glamoregl"',
>   }
>
> but this returns an error if the file doesn't exist, and I couldn't find a
> way of adding a conditional that will check whether the file exists in the
> 'file_line' module before it executes.
>
> Augeas could be a possibility, but I couldn't see a way of doing it in a
> simple way.
>
> Any suggestions welcome.
>
> Thanks,
>
> Cam
>
> --
> 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 puppet-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/f0b10c43-3868-46f7-9257-fd1e795dc360%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



-- 
Email: t...@whatexit.org    Work: tlimonce...@stackoverflow.com
Skype: YesThatTom
Blog:  http://EverythingSysadmin.com

-- 
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 puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/CAHVFxg%3DLpUcvgucQ_B9OVE0oT6PToSJkz6YO8UU7dTdOUiwSCQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to