首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用单个木偶erb模板创建两个内容不同的文件

如何使用单个木偶erb模板创建两个内容不同的文件
EN

Stack Overflow用户
提问于 2021-08-12 15:00:17
回答 1查看 135关注 0票数 0

我试图使用一个模板文件来创建Solaris 11 /etc/hosts.deny和/etc/hosts.allow文件,其中hiera数据位于data/Solaris.json。

如何使hosts.deny文件只包含"ALL: ALL",而hosts.allow包含"ALL: ALL“--即Solaris.json文件中的变量内容?

应该注意的是,我的组织正在使用Puppet5.5开放源码,使用了ruby模板和json,而不是yaml。

这是舱单。

代码语言:javascript
复制
class etc::solaris_hosts_files (
  Array[String] $entry,
) {
  file { 'hosts.allow': # Creates /etc/hosts.allow using template.
    ensure  => 'present',
    content => template('etc/solaris_hosts_template.erb'),
    owner   => 'root',
    group   => 'other',
    path    => '/etc/hosts.allow',
    mode    => '0444',
  }

  file { 'hosts.deny': # Creates /etc/hosts.deny using template.
    ensure  => 'present',
    content => template('etc/solaris_hosts_template.erb'),
    owner   => 'root',
    group   => 'other',
    path    => '/etc/hosts.deny',
    mode    => '0444',
  }
}

这是模板文件。

代码语言:javascript
复制
ALL: ALL
<% unless $etc::solaris_hosts_files::hosts.allow -%>
<%= @entry.join(' ') %>

下面是data/Solaris.json变量信息。

代码语言:javascript
复制
"etc::solaris_hosts_files::entry": [
        "<some_net>:<some_mask>",
        "<some_net>:<some_mask>  #<some_hostname>" ],

为了彻底起见,是的,@entry变量包含在data/common.json中。我们在Solaris.json中赋值。

代码语言:javascript
复制
"etc::solaris_hosts_files::entry": "",

我是菜鸟木偶师。任何帮助都将不胜感激。谢谢你!!

EN

回答 1

Stack Overflow用户

发布于 2021-08-12 16:54:41

贴出对马特·舒查德问题的答案。

hosts.deny

ALL: ALL

hosts.allow:

代码语言:javascript
复制
ALL: ALL
<ip>:<mask>
<ip>:<mask>

ip:掩码来自hiera数据。

呈现的结果是一个错误:

代码语言:javascript
复制
Info: Retrieving locales
Info: Loading facts
Error: Could not retrieve catalog from remote server: No content type in http response; cannot parse
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68759839

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档