arrays in puppet
- by paweloque
I'm wondering how to solve the following puppet problem: I want to create several files based on an array of strings. The complication is that I want to create multiple directories with the files:
dir1/
fileA
fileB
dir2/
fileA
fileB
fileC
The problem is that the file resource titles must be unique. So if I keep the file names in an array, I need to iterate over the array in a custom way to be able to postfix the file names with the directory name:
$file_names = ['fileA', 'fileB']
$file_names_2 = [$file_names, 'fileC']
file {'dir1': ensure => directory }
file {'dir2': ensure => directory }
file { $file_names: path = 'dir1', ensure =>present, }
file { $file_names_2: path = 'dir2', ensure =>present, }
This wont work because the file resource titles clash. So I need to append e.g. the dir name to the file title, however, this will cause the array of files to be concatenated and not treated as multiple files...
arghh..
file { "${file_names}-dir1": path = 'dir1', ensure =>present, }
file { "${file_names_2}-dir2": path = 'dir1', ensure =>present, }
How to solve this problem without the necessity of repeating the file resource itself.
Thanks