Puppet 实现定义用户

Puppet 实现定义用户

主要是作为学习练习,我尝试使用定义来创建用户。没有错误,但没有创建用户。添加对通知的调用让我怀疑问题出在执行顺序上(但也可能是我在其他地方的新手)。我使用的是 Puppet 2.7.9。

这是我的代码。

    # manifests/nodes.pp
    node /song.*/ {
      include users
      User <| group == developers |>
    }

    # modules/users/manifests/init.pp
    class users {
      include users::people
    }

    # modules/users/manifests/people.pp 
    class users::people {
      require groups
      @users::account { "michael":
          username => "michael",
          name     => "Michael C. Harris",
          uid      => 1000,
          gid      => "developers",
          password => '{encrypted password}',
          groups   => [ "wheel" ],
      }
    }

    # modules/groups/manifests/init.pp
    class groups {
      Group { ensure => present }
      group { "wheel":
        gid => 10;
      }
      group { "developers":
        gid => 1001;
      }
    }

    # modules/users/manifests/account.pp
    define users::account($ensure=present, managehome='true', allowdupe='false', homeprefix='/home', $username, $name, $password, $uid, $gid, $groups=[], $key='', $keytype='ssh-rsa', shell='/bin/zsh') {

      File { owner => $username, group => $username, mode => '0600' }

      $home = "${homeprefix}/${username}"

      user { $username:
        ensure     => $ensure,
        uid        => $uid,
        gid        => $gid,
        password   => $password,
        comment    => "$name",
        groups     => $groups,
        shell      => "$shell",
        home       => $home,
        require    => Group["$gid"],
        allowdupe  => $allowdupe,
        managehome => $managehome;
      }

      file { "$home":
        ensure => directory
      }
      if $key {
        file { "$home/.ssh":
            ensure => directory;
        }
        ssh_authorized_key { "$username":
          user    => $username,
          require => File["$home/.ssh"],
          key     => $key,
          type    => $keytype,
          ensure  => present;
        }
      }
    }

如果这是依赖关系问题,那么指定依赖关系的最佳方法是什么?还是我做错了什么?也欢迎大家提供一般反馈。

答案1

Puppet 可能甚至没有尝试创建用户,因为你正在创建一个虚拟用户帐号资源(您指定“@”),但只是试图实现一个用户资源(没有虚拟用户资源)。

此外,过滤器组==开发人员不会匹配任何内容,因为没有团体属性用户, 或者用户帐号

尝试替代用户 <| 组 == 开发人员 |>用户::帐户<| gid == 开发人员 |>看看是否有帮助。

相关内容