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.conf
Error: /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.conf
Error: /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.