Hi It may have been answered earlier but I could not find anywhere. My requirement is that I want to copy a file from server to agent in few conditions but don''t want to touch file in rest of the condition class example { case $hostname { node1 : {$conf_file = ''file1''} node2: {$conf_file = ''file2''} } file { ''/etc/network/test'': ensure => file, source => "puppet:///modules/example/ $conf_file", } } It is working but I want that in case none of the above condition is true then ''test'' file should not be touched. But what is happening here that, if hostname is different from node1 or 2 then puppet creates a empty test directory in /etc/network/ folder. Any suggestion ? thanks Kashif -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Wrap the file resource in an if that checks if $conf_file is defined. I would also recommend replacing the case statement with a parametrized class with the default for $conf_file being undef. Also, if you were okay with having a default blank file present then you could just replace your current case statement with a list to the file source attribute: file { "/path/to/my/file": source => [ "/modules/nfs/files/file.$host", "/modules/nfs/files/file" ] } http://docs.puppetlabs.com/references/2.7.0/type.html On Feb 1, 6:21 am, kashif <kashif.a...@gmail.com> wrote:> Hi > It may have been answered earlier but I could not find anywhere. My > requirement is that I want to copy a file from server to agent in few > conditions but don''t want to touch file in rest of the condition > > class example { > case $hostname { > node1 : {$conf_file = ''file1''} > node2: {$conf_file = ''file2''} > } > file { ''/etc/network/test'': > ensure => file, > source => "puppet:///modules/example/ > $conf_file", > } > } > > It is working but I want that in case none of the above condition is > true then ''test'' file should not be touched. > But what is happening here that, if hostname is different from node1 > or 2 then puppet creates a empty test directory in /etc/network/ > folder. > Any suggestion ? > thanks > Kashif-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Feb 1, 8:21 am, kashif <kashif.a...@gmail.com> wrote:> Hi > It may have been answered earlier but I could not find anywhere. My > requirement is that I want to copy a file from server to agent in few > conditions but don''t want to touch file in rest of the condition > > class example { > case $hostname { > node1 : {$conf_file = ''file1''} > node2: {$conf_file = ''file2''} > } > file { ''/etc/network/test'': > ensure => file, > source => "puppet:///modules/example/ > $conf_file", > } > } > > It is working but I want that in case none of the above condition is > true then ''test'' file should not be touched. > But what is happening here that, if hostname is different from node1 > or 2 then puppet creates a empty test directory in /etc/network/ > folder. > Any suggestion ?class example { case $hostname { node1 : {$conf_file = ''file1''} node2: {$conf_file = ''file2''} default: {$conf_file = ''''} } if $conf_file != '''' { file { ''/etc/network/test'': ensure => file, source => "puppet:///modules/example/$conf_file", } } } Note that this leaves File[''/etc/network/test''] *unmanaged* for nodes other than node1 and node2, which is quite a different thing from ensuring it absent or empty. You might want to consider those options too. Note also that the above will ensure at every Puppet run that the contents of /etc/network/test are exactly what the same as those of the master''s specified file. If you don''t want to keep the file contents synchronized with the master after the file is initially copied (or created some other way) then add "replace => false" to the File resource''s parameters. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.