Module hiera木偶中模块的基本用法

Module hiera木偶中模块的基本用法,module,puppet,hiera,Module,Puppet,Hiera,我想使用puppet来管理一些服务器。即使在阅读了几十页文档之后,我也不清楚如何使用模块以及如何将它们与hiera一起使用。作为第一个实验,我希望在一个节点上创建一个用户“admin”,并找到这个模块-> My/etc/puppet/hiera.yaml看起来就这么简单 --- :backends: - yaml :hierarchy: - node/%{::fqdn} - common :yaml: :datadir: /etc/puppet/hieradata My/etc

我想使用puppet来管理一些服务器。即使在阅读了几十页文档之后,我也不清楚如何使用模块以及如何将它们与hiera一起使用。作为第一个实验,我希望在一个节点上创建一个用户“admin”,并找到这个模块->

My/etc/puppet/hiera.yaml看起来就这么简单

---
:backends:
  - yaml
:hierarchy:
  - node/%{::fqdn}
  - common
:yaml:
  :datadir: /etc/puppet/hieradata
My/etc/puppet/hieradata/node/node1.example.com.yaml包含以下内容

---
accounts::users:
  admin:
    uid: 1010
    comment: admin
accounts::ssh_keys:
  admin:
    comment: ad
    type: ssh-rsa
    public: AAAAAAAAAAAAAA
在我把它放到我的/etc/puppet/manifests/site.pp中之后,它就工作了

hiera_include('classes')

class
{
    'accounts':
    ssh_keys   => hiera_hash('accounts::ssh_keys', {}),
    users      => hiera_hash('accounts::users', {}),
    usergroups => hiera_hash('accounts::usergroups', {}),
}

accounts::account
{
    'admin':
}

这是好的做法吗?对我来说,把这些东西放进site.pp是不对的,因为当我以后使用更多的模块时,它会变得一团糟。但还有什么地方可以放呢?我也不明白这是如何将数据和逻辑分开的,因为我在node1.example.com.yaml和site.pp(admin)中都有数据。一些帮助将非常有用。

要理解hiera是什么,您应该简单地认为hiera是puppet的数据库,是变量/值的数据库,仅此而已

对于初学者,我建议专注于系统的其他部分,比如如何创建模块!以及如何管理你的需求(没有复杂性),然后慢慢建立“智能”食谱或可重复使用的食谱

您的puppet首先会因为一个名为sites.pp的文件(通常位于主$confdir(puppet.conf变量)上)而生病

e路径是/etc/puppet,在该目录中,您有一个目录清单

通常,sites.pp结构是:

node default {
  include *module*
  include *module2*
}

node /server\.fqdn\.local/ {
  include *module2*
  include *module3*
}
这意味着您有一个默认节点(如果节点名称不适合任何其他节点,则将使用默认名称,否则在本例中将使用节点FQDN的正则表达式匹配server.FQDN.local)

模块(module、module2和module3)存储在puppet.conf上的$modulePath集合中。在本例中,我将使用:/etc/puppet/modules

这棵树看起来像:

/etc/puppet/modules/
/etc/puppet/modules/module/
/etc/puppet/modules/module/manifests/
/etc/puppet/modules/module/manifests/init.pp
/etc/puppet/modules/module2/
/etc/puppet/modules/module2/manifests/
/etc/puppet/modules/module2/manifests/init.pp
/etc/puppet/modules/module3/
/etc/puppet/modules/module3/manifests/
/etc/puppet/modules/module3/manifests/init.pp
关于 课程:
一般来说,我是从puppet实验室解释的:

请注意

3.x
之前的Puppet版本的用户提供服务,该版本没有。对于最新版本,您应该只使用以下清单:

include accounts

由于Hiera键有合适的名称,Puppet会隐式地查找它们。

这整件事对我来说仍然毫无意义。因为我必须

accounts::account
{
    'admin':
}

在创建该用户的清单文件中,hiera在这种情况下有什么用处?它没有将数据与逻辑分开。我在.yaml文件(ssh密钥、其他帐户数据)和清单文件(上面的代码段)中都有数据。通过使用hiera,我希望能够在/etc/puppet/hieradata/node/node1.example.com.yaml中创建该用户,但事实并非如此。这样做的正确方法是什么?此模块的示例hiera文件有何用处?在site.pp中以旧式方式创建帐户不是更容易吗?

我不同意。在puppet
3.7.x
和稍后,用户应该从一开始就使用环境。将自己限制在
生产环境中是完全可以的,但是忽略环境意味着以后必须更改木偶设置,这总是很痛苦的。你是对的。这是我的错误。这是一个如何使用木偶基本树的示例。@FelixFrank是ri嗯!
accounts::account
{
    'admin':
}