木偶无法使用keys()和hiera_hash()

时间:2018-08-02 23:22:15

标签: puppet

我在hiera节点中有变量solr_enabled = true。我在这个节点上也有fstab挂载点列表,例如:

fstab_homes:
'/home1':
device: 'UUID=ac2ca97e-8bce-4774-92d7-051482253089'
'/home2':
device: 'UUID=d9daaeed-4e4e-40e9-aa6b-73632795e661'
'/home3':
device: 'UUID=21a358cf-2579-48cb-b89d-4ff43e4dd104'
'/home4':
device: 'UUID=c68041de-542a-4f72-9488-337048c41947'
'/home16':
device: 'UUID=d55eff53-3087-449b-9667-aeff49c556e7'

在solr.pp中,我想获取第一个已安装的主磁盘,在该目录中创建一个文件夹,并建立指向/ home / cpanelsolr的符号链接。

为此,我编写了代码/etc/puppet/environments/testing/modules/cpanel/manifests/solr.pp

# Install SOLR - dovecot full text search plugin

class cpanel::solr(
    $solr_enable = hiera('solr_enabled',false),
    $homes = hiera_hash('fstab_homes', false),
    $homesKeys = keys($homes),
  )
{
if $solr_enable == true {
    notify{"Starting Solr Installation ${homesKeys[0]}":}
    if $homes != false and $homesKeys[0] != '/home' {
        file { "Create Solr home symlink to ${homesKeys[0]}":
           path => '/home/cpanelsolr',
           ensure => 'link',
           target => "${homesKeys[0]}/cpanelsolr",
        }
    }

    exec { 'cpanel-dovecot-solr':
        command => "/bin/bash -c 
'/usr/local/cpanel/scripts/install_dovecot_fts'",
      }
  }
}

但是当我在开发节点中运行它时,我得到了错误:

root@webcloud2 [/home1]# puppet agent -t --no-use_srv_records --server=puppet.development.internal --environment=testing --tags=cpanel::solr
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
2018-08-03  6:04:54 140004666824672 [Note] libgovernor.so found
2018-08-03  6:04:54 140004666824672 [Note] All governors functions found too
2018-08-03  6:04:54 140004666824672 [Note] Governor connected
2018-08-03  6:04:54 140004666824672 [Note] All governors lve functions found too
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: keys(): Requires hash to work with at 
/etc/puppet/environments/testing/modules/cpanel/manifests/solr.pp:6 on node webcloud2.development.internal
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

怎么了?

1 个答案:

答案 0 :(得分:3)

您在那里至少有两个问题。

第一个问题是在这种情况下根本不会设置$home。您将需要重写为:

class cpanel::solr(
    $solr_enable = hiera('solr_enabled',false),
    $homes = hiera_hash('fstab_homes', false),
  )
{
  $homes_keys = keys($homes)
  ...
}

第二个问题是您的YAML没有正确缩进,因此fstab_homes实际上不会返回哈希。应该是:

fstab_homes:
  '/home1':
    device: 'UUID=ac2ca97e-8bce-4774-92d7-051482253089'
  '/home2':
    device: 'UUID=d9daaeed-4e4e-40e9-aa6b-73632795e661'
  '/home3':
    device: 'UUID=21a358cf-2579-48cb-b89d-4ff43e4dd104'
  '/home4':
    device: 'UUID=c68041de-542a-4f72-9488-337048c41947'
  '/home16':
    device: 'UUID=d55eff53-3087-449b-9667-aeff49c556e7'

最后,请注意,在Puppet的参数名称中使用camelCase可能会在某些情况下引起问题,因此最好使用snake_case