【问题标题】:define keystone_user from openstack/puppet-keystone via hiera?通过 hiera 从 openstack/puppet-keystone 定义 keystone_user?
【发布时间】:2016-08-08 21:11:43
【问题描述】:

我正在使用https://github.com/openstack/puppet-keystone 设置 OpenStack 管理/控制器节点。我需要将'glance'用户添加到keystone。我想在我的 hiera 数据中尽可能多地尝试和做,这样我的清单就会很简单。

这是我的清单:

class kilo2_keystone {
    include controller_ceph
    include keystone
    include keystone::config
    include keystone::user
#    keystone_user { 'glance':
#        ensure => present,
#    }

}

注释掉的部分有效,但我希望能够做到 include keystone::user 并在我的 hiera 数据中提供参数,如下所示:

keystone::user: 
   "%{hiera('glance_admin_user')}":
      ensure: present

但是当我在我的节点上运行 puppet agent -t 时,我得到了这个错误:

Could not find class ::keystone::user

【问题讨论】:

  • 该模块中似乎没有用户类,那么您想用include keystone::user 做什么?此外,如果您正在像这样在 hiera 中定义资源,那么您想在查找时使用 create_resources 之类的东西。您使用的是 Hiera

标签: puppet openstack keystore hiera openstack-glance


【解决方案1】:

注释掉的代码声明了一个keystone_user 类型的资源,而不是一个类。据推测,它的类型keystone_user 是由 puppet-keystone 模块提供的。 include() 系列函数用于声明类,而不是资源,因此不适用于 keystone_user

有不止一种方法可以继续。如果您不希望出现比声明一个或多个keystone_users 更复杂的事情,那么我建议为您的类提供一个用户名参数,您可以通过 Hiera 为其分配一个值:

class kilo2_keystone($usernames = []) {
  include controller_ceph
  include keystone
  include keystone::config

  keystone_user { $usernames:
    ensure => present,
  }
}

另一方面,如果您希望能够声明多个用户,每个用户都有自己的一组属性,那么create_resources() 函数可能是阻力最小的路径。您仍然希望参数化您的类,以便它通过自动数据绑定从 Hiera 获取数据,但现在您希望数据具有不同的结构,如 create_resources() 文档中所述:作为哈希映射资源标题(用户名,在你的情况)到资源参数的内部散列到相应的值。

例如,您的班级可能如下所示:

class kilo2_keystone($userdata = {}) {
  include controller_ceph
  include keystone
  include keystone::config

  create_resources('keystone_user', $userdata)
}

该类的对应数据可能如下所示:

kilo2_keystone::userdata:
  glance:
    ensure: present
    enabled: true
  another_user:
    ensure: absent

还请注意,您将kilo2_keystone 类放在顶级范围内。你真的应该把它放在一个模块中并将它分配给那个模块的命名空间。后者看起来像这样:

class mymodule::kilo2_keystone($userdata = {}) {
  # ...
}

【讨论】:

  • 此外,您不能在 hieradata 中进行 hiera 查找,这是问题示例中的其他内容。
  • @MattSchuchard,您可以在 hiera 数据中进行 hiera 查找;见docs.puppet.com/hiera/3.2/variables.html#using-lookup-functions。该链接适用于 Hiera 3.2 文档,但该功能一直记录到 Hiera 1。
  • 这似乎是不可能的事情,这一定是我直到现在才看到它在使用的原因。很有趣。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-06
相关资源
最近更新 更多