我希望能够根据数组的内容创建文件。这是我尝试过的:
class make_files (
$servers = ['server-1','server-2','server-3'],
) {
file { $servers :
path => '/tmp',
content => $servers,
}
}
...但是当我这样执行时......
# puppet apply --modulepath=/root/modules -e 'include make_files'
...我得到了这个输出:
Notice: Compiled catalog for host-001 in environment production in 0.13 seconds
Error: Cannot alias File[server-2] to ["/tmp"] at /root/modules/make_files/manifests/init.pp:9; resource ["File", "/tmp"] already declared at /root/modules/make_files/manifests/init.pp:9
我希望有三个档案......
# ls /tmp/server-?
/tmp/server-1 /tmp/server-2 /tmp/server-3
# cat /tmp/server-?
server-1
server-2
server-3
如果有人能告诉我如何命名文件,那将真的很酷:server-1.cfg,server-2.cfg和server-3.cfg。 感谢任何帮助!
答案 0 :(得分:1)
首先,您已在File['/tmp']
文件中定义了资源init.pp
。
这是导致问题的主要原因:
错误:无法在/root/modules/make_files/manifests/init.pp:9将文件[server-2]别名为[“/ tmp”];资源[“File”,“/ tmp”]已在/root/modules/make_files/manifests/init.pp:9中声明
请检查path属性的含义。也许这会澄清问题。 创建
$files_to_create = ['/path/server-1','/path/server-2','/path/server-3']
然后使用它:
file { $files_to_create :
content => $servers,
}
还请确保文件系统中已存在/path
目录。到目前为止,puppet无法创建中间目录。