微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

centos – 管理启用 – 禁用Hiera puppet的nginx网站?

我得到了实现hiera puppet脚本来管理Nginx的sites_enabled的任务.

这是我的傀儡剧本:

common.yaml

---
classes:
    - Nginx

Nginx:
    enabled:
        abc.com
        xyz.com
    disabled:
        test.com
        test2.com

init.pp

class Nginx{
    create_resources("site_enabled",hiera("Nginx"),{})
}

define site_enabled($name){
    file { '/etc/Nginx/sites_enabled/${name}':
       ensure => 'link',target => '/etc/Nginx/site_available/${name}',}
}

但是当木偶执行时我得到了错误

err: Could not retrieve catalog from Remote Server: Error 400 on
SERVER: can’t convert String into Integer at
/etc/puppet/modules/Nginx/manifests/init.pp:7 on node XX

当我试图通过命令行查询hiera时:

$hiera Nginx

{“enabled”=>[“abc.com”,“xyz.com”]}

我知道我错了一些地方.请你好好指正.
我不太了解,如何使用数组数据查询和处理.如果可能的话,请指出一些有用的文件.

非常感谢.

你的问题非常类似于 Problems creating Hiera hashes for create_resources,它有一个答案.我在这里提供一个回顾.

根据documentation for create_resources,哈希必须采用{title =>形式{parameters}}.您应该编辑hiera数据以设置参数.由于没有,我认为它可能看起来像这样:

common.yaml

---
classes:
    - Nginx

Nginx::enabled:
    abc.com: {}
    xyz.com: {}
Nginx::disabled:
    test.com: {}
    test2.com: {}

接下来,您需要实际从hiera加载正确的数据.你想加载Nginx :: enabled,而不是所有的Nginx

init.pp

class Nginx{
    create_resources("site_enabled",hiera("Nginx::enabled"))
}

define site_enabled($name){
    file { '/etc/Nginx/sites_enabled/${name}':
       ensure => 'link',}
}

原文地址:https://www.jb51.cc/centos/373547.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。