与 hiera 和 puppet 中的所有虚拟主机共享 nginx 状态位置

sharing nginx status location with all vhosts in hiera and puppet

我正在使用 Jfryman puppet nginx 模块,我正在尝试使用可用的虚拟主机启用状态定位,所以我的 hiera 是这样的:

---
nginx::nginx_vhosts:
  'default':
    www_root: '/www/default'
    listen_port: 8081

  'default2':
    www_root: '/www/default2'
    listen_port: 8082

  'default3':
    www_root: '/www/default3'
    listen_port: 8083

nginx::nginx_locations:
  'status':
    location: '/status'
    vhost: 'default'...."here wanna include more than one vhost"
    stub_status: true

是否可以在不复制 hiera 条目的情况下将这个位置包含在这些 vhost 中?

不,location type takes only one vhost parameter and uses it to determine the target file

为了保持干燥,您必须避免使用 nginx class 的 nginx_locations 参数,并自行声明 nginx::resource::location 实例。

define status_location_for_vhost() {
    nginx::resource::location { "status-for-$name":
        location => '/status',
        vhost    => $name,
        stub_status => true
    }
}

声明每个虚拟主机的那些。