I know that file_line should autorequire the file since it's being managed, 
so the "require"s aren't strictly necessary.

To test for the file's existence, you'll need to write a custom fact. See 
this for 
suggestions: 
http://stackoverflow.com/questions/18784329/how-to-test-for-existence-of-a-file-on-the-puppet-master


Bret

On Friday, July 8, 2016 at 1:01:28 PM UTC-4, mike r wrote:
>
> Quick question, Im writing a module that makes sure file_line exists but 
> cant figure out how to only apply this if the target file exists, heres the 
> module so far
>
>
> $file = '/etc/modprobe.d/CIS.conf'
>
> file { $file :
>   ensure => file,
>   mode   => '0600',
>   owner  => 'root',
>   group  => 'root',
> }
>
>
> file_line { "(1.1.18) ${file} - cramfs":
>   ensure  => present,
>   path    => $file,
>   line    => 'install cramfs /bin/true',
>   require => File[$file],
> }
>
> file_line { "(1.1.19) ${file} - freevxfs":
>   ensure  => present,
>   path    => $file,
>   line    => 'install freevxfs /bin/true',
>   require => File[$file],
> }
>
>
> I added the Require for each file_line but when I test on a node I get 
> this, 
>
> *Notice: 
> /Stage[main]/Cis_rhel7::Rule::Rule_1_1_18/File[/etc/modprobe.d/CIS.conf]/ensure:
>  
> current_value absent, should be file (noop)*
>
>
> *Error: /Stage[main]/Cis_rhel7::Rule::Rule_1_1_18/File_line[(1.1.18) 
> /etc/modprobe.d/CIS.conf - cramfs]: Could not evaluate: No such file or 
> directory @ rb_sysopen - /etc/modprobe.d/CIS.confError: 
> /Stage[main]/Cis_rhel7::Rule::Rule_1_1_18/File_line[(1.1.19) 
> /etc/modprobe.d/CIS.conf - freevxfs]: Could not evaluate: No such file or 
> directory @ rb_sysopen - /etc/modprobe.d/CIS.confError: 
> /Stage[main]/Cis_rhel7::Rule::Rule_1_1_18/File_line[(1.1.20) 
> /etc/modprobe.d/CIS.conf - jffs2]: Could not evaluate: No such file or 
> directory @ rb_sysopen - /etc/modprobe.d/CIS.conf*
> Error: /Stage[main]/Cis_rhel7::Rule::Rule_1_1_18/File_line[(1.1.21) 
> /etc/modprobe.d/CIS.conf - hfs]: Could not evaluate: No such file or 
> directory @ rb_sysopen - /etc/modprobe.d/CIS.conf
> Error: /Stage[main]/Cis_rhel7::Rule::Rule_1_1_18/File_line[(1.1.22) 
> /etc/modprobe.d/CIS.conf - hfsplus]: Could not evaluate: No such file or 
> directory @ rb_sysopen - /etc/modprobe.d/CIS.conf
> Error: /Stage[main]/Cis_rhel7::Rule::Rule_1_1_18/File_line[(1.1.23) 
> /etc/modprobe.d/CIS.conf - squashfs]: Could not evaluate: No such file or 
> directory @ rb_sysopen - /etc/modprobe.d/CIS.conf
> Error: /Stage[main]/Cis_rhel7::Rule::Rule_1_1_18/File_line[(1.1.24) 
> /etc/modprobe.d/CIS.conf - udf]: Could not evaluate: No such file or 
> directory @ rb_sysopen - /etc/modprobe.d/CIS.conf
> Info: Class[Cis_rhel7::Rule::Rule_1_1_18]: Unscheduling all events on 
> Class[Cis_rhel7::Rule::Rule_1_1_18]
>
> All my resources are have a resource default of NOOP, since Im doing a 
> compliance check. Cant figure out how to make File_line only get applied if 
> the file exists. 
>

-- 
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/e3d4ac1a-7249-473f-a65f-4cc555f7946b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to