AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 816909
Accepted
Skullone
Skullone
Asked: 2016-11-25 10:05:58 +0800 CST2016-11-25 10:05:58 +0800 CST 2016-11-25 10:05:58 +0800 CST

Puppet/hiera : 从一个模板生成多个文件

  • 772

我正在运行 puppet 4,我想从同一个模板生成几个配置文件,每个配置文件都有不同的配置。

例如 :

# cat /tmp/a.conf 
test1

# cat /tmp/b.conf 
test2

而且我需要将所有这些信息放在 hiera 中,所以我认为是这样的:

test::clusters:
  - 'a.conf'
    text: 'test1'
  - 'b.conf'
    text: 'test2'

谢谢

puppet template puppetmaster hiera
  • 2 2 个回答
  • 796 Views

2 个回答

  • Voted
  1. jaxxstorm
    2016-11-25T10:57:23+08:002016-11-25T10:57:23+08:00

    你需要一个定义的类型

    define test::clusters (
      $text = undef
    ) {
    
      file { "/tmp/${title}":
        ensure  => $ensure,
        owner   => 'root',
        group   => 'root',
        content => template('my_file/example.erb'),
      }
    
    }
    

    在模板/测试/集群中

    <%= @text %>
    

    然后您可以test::clisters像这样在清单中定义 a :

    ::test::clusters { 'a.conf':
      text => 'test1'
    }
    

    或者如果您仍然希望使用 hiera,您可以使用create_resources

    • 2
  2. Best Answer
    Skullone
    2016-11-25T12:12:58+08:002016-11-25T12:12:58+08:00

    好的,我找到了使它起作用的方法:

    这是我的 hiera data/common.yaml :

    test::paramconf:
      'a':
        text: '1'
      'b':
        text: '2'
    

    这是我的模块配置 manifests/init.pp :

    class test ($paramconf){
        create_resources(test::conf, $paramconf)
    }
    
    define test::conf (
      String[1] $text,
      String[1] $text2 = $title,
    ) {
      file { "/tmp/${title}.conf":
        ensure  => file,
        owner   => 'root',
        group   => 'root',
        mode    => '0644',
        content => template('test/test2.erb'),
      }
    }
    

    我唯一不明白的是为什么这是有效的:

    test::paramconf:
      'a':
        text: '1'
      'b':
        text: '2'
    

    这不起作用:

    test::paramconf:
      - 'a':
        text: '1'
      - 'b':
        text: '2'
    
    • 0

相关问题

  • 如何修复 Puppet 完全限定的参数路径错误?

  • puppet:修改配置文件后强制重启服务

  • 木偶模块资源

  • 傀儡主机名问题

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve