1

I'm trying to set a custom .vimrc profile on all servers in the production environment by using Puppet.

I wrote the following manifest:

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",
    }
}

The first part of the manifest works like a charm and adds a .vimrc file to /etc/skel, but for some reason, the second part doesn't work, even though you can see it's exactly the same configuration apart from the path, the path in the second section is root's home directory.

Is there a reason why Puppet ignores this section?

Is that because it has some defenses when it comes to root's home folder?

Edit #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 ~]#

Edit #2: When running puppet agent -t on the client, I get the following output:

[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 ~]#

When checking the problematic file in the Puppet server:

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

node default {
}
[root@foreman fqdns]#

As you can see, it says there's an issue with line 11 but there are only 5 lines in the file.

4
  • 2
    There is an extra } after the first file resource closing the vim class. That might fix it already...
    – Sven
    Feb 10, 2015 at 9:05
  • That's true and i've fixed it, but the issue persists, the first section works and the second doesn't.
    – Itai Ganot
    Feb 10, 2015 at 10:43
  • Can you post the output of ls -la /root/? Feb 10, 2015 at 10:54
  • @CraigWatson, please check Edit #1, thanks.
    – Itai Ganot
    Feb 10, 2015 at 10:57

2 Answers 2

1

As Sven points out in his comment, this is actually a syntax error in your code - you have an extra } at the end of your first file resource.

To expand on this, this isn't actually considered 'invalid' syntax as such - hence why Puppet still runs and doesn't complain. You're effectively ending the class with the second }, and anything after that is ignored by Puppet.

Also, a few style points:

  • Your mode attribute needs to be '0644' [ Source: Puppet docs ]
  • You only need to double-quote strings when you're using a variable/fact within them (i.e. "This is a string quoting ${myvar}." [ Source: Puppet Lint ]
  • You can remove the path attribute entirely if you use the path for the name of the resource [ Source: Puppet docs ]

Try with this code:

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',
    }
}
2
  • Thanks, just tried it... I receive an error which is just a little bit different from the one in my Edit #2.
    – Itai Ganot
    Feb 10, 2015 at 11:07
  • You can view the difference between the errors here: pastebin.com/BaSprHdr
    – Itai Ganot
    Feb 10, 2015 at 11:10
1

Okay, I found the problem. I've mistakenly wrote the class in the hiera file instead of the modules directory of puppet. Once I moved the file to the modules/vim/manifests/ folder and edited the hiera file like so:

classes:
 - vim

It started working.

Thanks for your help.

1
  • Ah, that would have done it! Glad you got it sorted :) Feb 10, 2015 at 16:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .