3

I am trying to create a vagrant box to use for development with Puppet as provisioner. I want to set a specific .bashrc for the vagrant user.

Here are my relevant files.

dev.pp:

class dev {

    $target = "dev"
    $root_dir = "/home/vagrant/demo"
    $user = "demo"
    $group = "demo"

    class { "demo":
        target => $target,
        root_dir => $root_dir,
        user => $user,
        group => $group;
    }

    class { "demo::app::site": }

}

class { "dev": }

modules/demo/manifests/init.pp:

class demo ($target, $root_dir, $user, $group) {

    group { $group:
        ensure => present;
    }

    user { $user:
        ensure     => present,
        managehome => true,
        shell      => '/bin/bash',
        gid        => $user,
        require    => Group[$group];
    }

    file {
        $root_dir:
            owner   => $user,
            group   => $group,
            ensure  => directory,
            require => User[$user];        
    }

    file { "/home/${user}/.bashrc":
        ensure => present,
        owner   => $user,
        group   => $group,
        mode    => '755',
        content => template("${module_name}/bashrc.erb"),
        require => User[$user];
    }

    if $target == 'dev' {
        file { $source_dir:
            owner   => $user,
            group   => $group,
            ensure  => directory,
            require => [File[$root_dir], User[$user]];
        }
    }
}

modules/demo/manifests/user.pp:

define demo::user ($ensure=present, $groups=[]) {

  $user = $name

  user { $user:
    ensure     => $ensure,
    groups     => $groups,
    home       => "/home/$user",
    managehome => true,
    shell      => '/bin/bash';
  }

}

Everything seems to be working fine. I can execute "vagrant ssh" and I get the VM's command line prompt. But the .bashrc file is not the one defined here:

content => template("${module_name}/bashrc.erb"),

And if I delete it manually it never gets created again from "vagrant provision". It seems that the file resource definition is never being executed. I'm new to Puppet but I thought that everything that is declared in the class should be executed. And the class is being correctly required, because everything else works fine. Are there any ways for me to debug, using 'notify' is not helpful here.

  • 1
    do you have under "modules/demo/templates/bashrc.erb" ? – c4f4t0r Feb 15 '15 at 20:25
  • 1
    To debug you can pass --debug to puppet apply to see more. One question though: You say you want this file for the vagrant user, but you set $user = "demo". Is the issue that the file is not created in /home/demo? Or /home/vagrant? – faker Feb 15 '15 at 20:31
  • @c4f4t0r yes. In fact, if that file is not present, I get an error. I do not get any errors, but the .bashrc I get is not the one in the template. It seems to be a default one. – martincho Feb 16 '15 at 4:23
  • @faker you hit the nail on the head. That was the bug. $user should be "vagrant" instead of "demo". If you post the answer I'll accept it. – martincho Feb 16 '15 at 4:44
1

You wanted to manage /home/vagrant/.bashrc but you set:

$user = "demo"

which gets used later:

file { "/home/${user}/.bashrc":
    ensure => present,
    owner   => $user,

so you'll just need to change the user variable to vagrant.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.