Puppet 配置创建文件

Puppet 配置创建文件

我正在尝试创建一个 vagrant box 以用于开发,并使用 Puppet 作为配置器。我想为 vagrant 用户设置一个特定的 .bashrc。

这是我的相关文件。

开发手册

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

模块/演示/清单/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]];
        }
    }
}

模块/演示/清单/用户.pp:

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

  $user = $name

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

}

一切似乎都运行正常。我可以执行“vagrant ssh”,并获得虚拟机的命令行提示符。但 .bashrc 文件不是此处定义的文件:

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

如果我手动删除它,它永远不会从“vagrant provision”中再次创建。似乎文件资源定义从未被执行过。我是 Puppet 的新手,但我认为类中声明的所有内容都应该被执行。并且该类被正确要求,因为其他一切都运行良好。有什么方法可以让我调试,使用“通知”在这里没有帮助。

答案1

你想管理/home/vagrant/.bashrc但你设置了:

$user = "demo"

稍后会用到:

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

因此您只需将用户变量更改为 vagrant。

相关内容