覆盖 Puppet 用户帐户模块中的值

覆盖 Puppet 用户帐户模块中的值

我有一个可以在 Linux 机器上创建用户帐户的 Puppet 模块。

我正在尝试覆盖配置中用户 shell 和主目录的几个设置。我收到此错误:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Invalid parameter shell on Accounts::Virtual[mysql] at /etc/puppet/environments/production/modules/accounts/manifests/init.pp:70 on node solr1.jokefire.com
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

我在帐户模块的 init.pp 中以这种方式设置了用户虚拟帐户定义:

   @accounts::virtual { 'mysql':
     uid             =>  1007,
     shell           =>  '/bin/false',
     home            => '/var/lib/mysql',
     realname        =>  'mysql',
     pass            =>  'secret_hash',
    }

虚拟账户定义的设置方式如下:

# Defined type for creating virtual user accounts
#
define accounts::virtual ($uid,$realname,$pass) {

  user { $title:
    ensure            =>  'present',
    uid               =>  $uid,
    gid               =>  $title,
    shell             =>  '/bin/bash',
    home              =>  "/home/${title}",
    comment           =>  $realname,
    password          =>  $pass,
    managehome        =>  true,
    require           =>  Group[$title]
  }

  group { $title:
    gid               =>  $uid,
  }

  file { "/home/${title}":
    ensure            =>  directory,
    owner             =>  $title,
    group             =>  $title,
    mode              =>  0750,
    require           =>  [ User[$title], Group[$title] ]
  }
}

我哪里做错了?为什么我不能覆盖这些值?

答案1

您定义的类型没有 $shell 和 $home 参数。
目前只能设置 $uid、$realname 和 $pass。

您需要进行调整,例如像这样(未经测试):

# Defined type for creating virtual user accounts
#
define accounts::virtual (
  $uid,
  $realname,
  $pass,
  $shell = '/bin/bash',
  $home  = "/home/${title}",
) {

  user { $title:
    ensure            =>  present,
    uid               =>  $uid,
    gid               =>  $title,
    shell             =>  $shell,
    home              =>  $home,
    comment           =>  $realname,
    password          =>  $pass,
    managehome        =>  true,
    require           =>  Group[$title]
  }

  group { $title:
    gid               =>  $uid,
  }

  file { $home:
    ensure            =>  directory,
    owner             =>  $title,
    group             =>  $title,
    mode              =>  0750,
    require           =>  [ User[$title], Group[$title] ]
  }
}

这应该将这些参数的默认值设置为先前的值。
但也允许在声明时设置它们。

相关内容