puppet epp模板错误(无效的epp:语法错误位于)

puppet epp模板错误(无效的epp:语法错误位于),puppet,Puppet,我将尝试将erb迁移到epp并将不推荐的hiera\u hash迁移到lookup。 当前错误: Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Function Call, epp(): Invalid EPP: Syntax error at 'Port ' at /etc

我将尝试将
erb
迁移到
epp
并将不推荐的
hiera\u hash
迁移到
lookup
。 当前错误:

Error: Could not retrieve catalog from remote server: 
Error 500 on SERVER: Server Error: Evaluation Error: 
Error while evaluating a Function Call, epp(): Invalid EPP: 
Syntax error at 'Port ' at /etc/puppetlabs/code/environments/production/modules/sshd/templates/sshd_config.epp:4:24 
at /etc/puppetlabs/code/environments/production/modules/sshd/manifests/init.pp:23:16 on node puppettestnode
myinit.pp

class sshd {
  #$sshd_config = hiera_hash('sshd')
  $sshd=lookup('sshd', {merge => 'hash'})

  package { 'openssh-server':
    ensure => present,
    before => Service['sshd'],
  }

  file { '/etc/ssh':
    ensure  => directory,
    owner   => 'root',
    group => 'root',
    mode => '0755',
    require => Package['openssh-server']
  }->

  file { '/etc/ssh/sshd_config':
    owner   => 'root',
    group => 'root',
    mode => '0644',
    ensure  => file,
    content => epp("${module_name}/sshd_config.epp"),
  }~>

  service { 'sshd':
    ensure => running,
    require => [
      Package['openssh-server'],
      File['/etc/ssh/sshd_config'],
    ],
  }
}
###Managed by Puppet###

# What ports, IPs and protocols we listen for
<% if $sshd["port"] -%>
Port <%= $sshd["port"] %>
<% else -%>
Port 22
<% end -%>

# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
<% if $sshd['listen'] -%>
ListenAddress <%= $sshd['listen'] %>
<% else -%>
ListenAddress 0.0.0.0
<% end -%>
---
sshd:
  port: '22'
  listen: '0.0.0.0'
sshd_config.epp

class sshd {
  #$sshd_config = hiera_hash('sshd')
  $sshd=lookup('sshd', {merge => 'hash'})

  package { 'openssh-server':
    ensure => present,
    before => Service['sshd'],
  }

  file { '/etc/ssh':
    ensure  => directory,
    owner   => 'root',
    group => 'root',
    mode => '0755',
    require => Package['openssh-server']
  }->

  file { '/etc/ssh/sshd_config':
    owner   => 'root',
    group => 'root',
    mode => '0644',
    ensure  => file,
    content => epp("${module_name}/sshd_config.epp"),
  }~>

  service { 'sshd':
    ensure => running,
    require => [
      Package['openssh-server'],
      File['/etc/ssh/sshd_config'],
    ],
  }
}
###Managed by Puppet###

# What ports, IPs and protocols we listen for
<% if $sshd["port"] -%>
Port <%= $sshd["port"] %>
<% else -%>
Port 22
<% end -%>

# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
<% if $sshd['listen'] -%>
ListenAddress <%= $sshd['listen'] %>
<% else -%>
ListenAddress 0.0.0.0
<% end -%>
---
sshd:
  port: '22'
  listen: '0.0.0.0'
傀儡服务器的傀儡查找:

puppet lookup sshd --merge unique --environment production --explain
Searching for "sshd"
  Global Data Provider (hiera configuration version 5)
    Using configuration "/etc/puppetlabs/puppet/hiera.yaml"
    Merge strategy unique
      Hierarchy entry "Per-node data"
        Path "/etc/puppetlabs/code/environments/production/hiera/nodes/puppettestserver"
          Original path: "nodes/%{::fqdn}"
          Path not found
      Hierarchy entry "Common data"
        Path "/etc/puppetlabs/code/environments/production/hiera/common.yaml"
          Original path: "common.yaml"
          Found key: "sshd" value: {
            "port" => "22",
            "listen" => "0.0.0.0"
          }
      Merged result: [
        {
          "port" => "22",
          "listen" => "0.0.0.0"
        }
      ]

如果可能,请提供帮助。

if语句使用的是Ruby语法,而不是Puppet DSL语法,这会导致异常错误消息

模板应为:

###Managed by Puppet###

# What ports, IPs and protocols we listen for
<% if $sshd["port"] { -%>
Port <%= $sshd["port"] %>
<% } else { -%>
Port 22
<% } -%>

# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
<% if $sshd['listen'] { -%>
ListenAddress <%= $sshd['listen'] %>
<% } else { -%>
ListenAddress 0.0.0.0
<% } -%>

因此,您必须在EPP中使用相同的花括号。()。

if语句使用的是Ruby语法而不是Puppet DSL语法,这导致了异常错误消息

模板应为:

###Managed by Puppet###

# What ports, IPs and protocols we listen for
<% if $sshd["port"] { -%>
Port <%= $sshd["port"] %>
<% } else { -%>
Port 22
<% } -%>

# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
<% if $sshd['listen'] { -%>
ListenAddress <%= $sshd['listen'] %>
<% } else { -%>
ListenAddress 0.0.0.0
<% } -%>

因此,您必须在EPP中使用相同的花括号。()。

非常感谢,但现在我有另一个错误
求值错误:运算符“[]”不适用于未定义的值。在/etc/puppetlabs/code/environments/production/modules/sshd/templates/sshd\u config.epp:4:7 on node puppettestnode
$sshd
未定义时,您需要使用带有类名前缀(
$sshd:sshd
)的完全限定变量名,或在epp函数调用中传递它:
epp(${module\u name}/sshd config.epp”{“sshd”=>$sshd})
请参阅以获取详细信息。再次非常感谢。Variant
epp(${module\u name}/sshd\u config.epp),{“sshd”=>$sshd})
工作正常,但使用类前缀需要使用double
作为
$sshd::sshd
非常感谢,但现在我有另一个错误
评估错误:操作符'[]'不适用于未定义的值。在/etc/puppetlabs/code/environments/production/modules/sshd/templates/sshd_config.epp:4:7节点puppettestnode
$sshd
未定义时,需要使用带有类名前缀的完全限定变量名(
$sshd:sshd
)或将其传递到epp函数调用中:
epp('${module\u name}/sshd\u config.epp',{“sshd”=>$sshd})查看详细信息。再次感谢。变量
epp(${module\u name}/sshd\u config.epp',{“sshd”=>$sshd})
工作正常,但使用类前缀时需要使用双
as
$sshd::sshd