木偶:如何强制在根目录的文件夹中创build文件?

我试图通过使用Puppet在生产环境中的所有服务器上设置自定义的.vimrcconfiguration文件。

我写了下面的清单:

 class vim { file { "/etc/skel/.vimrc": path => '/etc/skel/.vimrc', ensure => present, mode => "664", source => "puppet:///modules/vim/.vimrc", } } file { "/root/.vimrc": path => '/root/.vimrc', ensure => present, mode => "664", source => "puppet:///modules/vim/.vimrc", } } 

清单的第一部分工作起来像一个魅力,并将.vimrc文件添加到/etc/skel ,但由于某种原因,第二部分不起作用,即使您可以看到它与path完全相同的configuration,第二部分的path是root的主目录

木偶是否有理由忽略这一部分?

那是因为它涉及到root的home文件夹有一些防御?

编辑#1:

 [root@sgproxy04 ~]# ls -la /root/ total 2452 dr-xr-x---. 3 root root 4096 2015-02-10 10:53 . dr-xr-xr-x. 27 root root 4096 2015-01-12 09:31 .. -rw-------. 1 root root 9423 2013-07-17 14:19 anaconda-ks.cfg -rw------- 1 root root 14032 2015-02-10 10:55 .bash_history -rw-r--r--. 1 root root 18 2009-05-20 10:45 .bash_logout -rw-r--r-- 1 root root 196 2014-11-17 12:16 .bash_profile -rw-r--r--. 1 root root 176 2004-09-23 03:59 .bashrc -rw-r--r--. 1 root root 9545 2013-07-17 14:21 cobbler.ks -rw-r--r--. 1 root root 100 2004-09-23 03:59 .cshrc -rwxr-xr-x. 1 root root 396 2013-07-10 07:33 hosts.sh -rw-r--r--. 1 root root 17440 2013-07-17 14:19 install.log -rw-r--r--. 1 root root 12476 2013-07-17 14:19 install.log.syslog -rw-r--r--. 1 root root 2382545 2013-07-17 14:21 ks-post.log -rw-r--r--. 1 root root 3572 2013-07-17 14:17 ks-pre.log drwx------ 2 root root 4096 2014-09-15 07:45 .ssh -rw-r--r--. 1 root root 129 2004-12-03 21:42 .tcshrc -rw-rw-r-- 1 root root 0 2014-12-18 16:14 testfile2.dat -rw-rw-r-- 1 root root 0 2014-12-18 16:14 testfile.dat -rw------- 1 root root 6757 2015-02-10 10:53 .viminfo [root@sgproxy04 ~]# 

编辑#2:当在客户端运行puppet agent -t时,我得到以下输出:

 [root@sgproxy04 ~]# puppet agent -t Info: Retrieving pluginfacts Info: Retrieving plugin Info: Loading facts in /var/lib/puppet/lib/facter/root_home.rb Info: Loading facts in /var/lib/puppet/lib/facter/pe_version.rb Info: Loading facts in /var/lib/puppet/lib/facter/puppet_vardir.rb Info: Loading facts in /var/lib/puppet/lib/facter/facter_dot_d.rb Error: Could not retrieve catalog from remote server: Error 400 on SERVER: syntax error on line 11, col 4: ` ensure => present,' at /etc/puppet/environments/production/manifests/site.pp:1 on node sgproxy04.sg.company.com Warning: Not using cache on failed catalog Error: Could not retrieve catalog; skipping run [root@sgproxy04 ~]# 

在Puppet服务器中检查有问题的文件时:

 [root@foreman fqdns]# cat /etc/puppet/environments/production/manifests/site.pp hiera_include("classes", []) Package { allow_virtual => false, } node default { } [root@foreman fqdns]# 

正如你所看到的,它表示第11行存在问题,但文件中只有5行。

正如Sven在他的评论中指出的那样,这实际上是代码中的一个语法错误 – 在第一个file资源的末尾有一个额外的}

为了扩大这一点,这实际上并不被认为是“无效的”语法 – 因此,为什么Puppet仍然运行,并没有抱怨。 你有效地结束了第二个类,之后的任何东西都被Puppet忽略。

另外,还有一些样式点:

  • 你的mode属性需要是'0644' [来源: 木偶文档 ]
  • 你只需要在他们内部使用一个variables/事实时(例如"This is a string quoting ${myvar}."双引号string"This is a string quoting ${myvar}." [来源: Puppet Lint ]
  • 如果您使用path作为资源的名称,则可以完全删除path属性[来源: Puppet文档 ]

试试这个代码:

 class vim { file { '/etc/skel/.vimrc': ensure => file, mode => '0664', source => 'puppet:///modules/vim/.vimrc', } file { '/root/.vimrc': ensure => file, mode => '0664', source => 'puppet:///modules/vim/.vimrc', } } 

好的,我发现了这个问题。 我错误地写了hiera文件而不是puppet的modules目录。 一旦我将文件移动到modules/vim/manifests/文件夹,并像这样编辑hiera文件:

 classes: - vim 

它开始工作。

谢谢你的帮助。