Ask Your Question
0

Hiera hash or array error

asked 2016-06-14 13:08:51 -0500

Gabor gravatar image

I developed an AWS S3 bakcup modul, but after the latest modify, puppet client not running (for run I using a following command: puppet agent --no-daemonize --debug --onetime).

My hiera.yaml:

---
:backends:
  - yaml
:yaml:
  :datadir: /etc/puppet/hieradata
:hierarchy:
  - "%{hostname}"
  - "%{domain}"
  - common
:merge_behavior: deeper

Common.yaml

awsbackupdetails:
  aws-region: "XYZ"
  aws-bucket-name: XYZ
  aws-access-key-id: "XYZ"
  aws-secret-acces-key: "XYZ"
  gpgkey: XYZ
  gpgpass: "XYZ"

xyz.hostname.lan.yaml

awss3backup:
  zurveysql:
    backuptype: database
    backuptypeselect: all
    backupdescription: ""

/etc/puppet/manifests/servergroups/server.pp

if(hiera('awss3backup')){
    include backupaws

    $awsbackupdetails = hiera('awsbackupdetails')

    class {
        'backupaws::credentials':
            aws_region           => $awsbackupdetails['aws-region'],
            aws_bucket_name      => $awsbackupdetails['aws-bucket-name'],
            aws_access_key_id    => $awsbackupdetails['aws-access-key-id'],
            aws_secret_acces_key => $awsbackupdetails['aws-secret-acces-key'];
        'backupaws::gnupg':
            gpgkey  => $awsbackupdetails['gpgkey'],
            gpgpass => $awsbackupdetails['gpgpass'];
    }

    $awss3backup = hiera('awss3backup')
    create_resources('backupaws::duply', $awss3backup)
}

/etc/puppet/modules/backupaws/manifests/duply.pp (detail):

$var = $awsbackupdetails['aws-bucket-name']

exec {
    "${name}_AWS_S3_Initialization":
        refreshonly => true,
        cwd         => "/root/.duply/${hostname}-${name}/",
        command     => "aws s3 cp .backupdetails.txt s3://${var}/${$hostname}/${name}/backupdetails.txt",
        path        => '/usr/local/bin/';
}

I gave a following error in puppet client:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: awsbackupdetails is not a hash or array when accessing it with aws-bucket-name at /etc/puppet/modules/backupaws/manifests/duply.pp:30 on node ntc-hun-zurveydb01.dhq.neticle.net

Any idea ?

Thank you!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-06-15 11:31:02 -0500

jon6000 gravatar image

updated 2016-06-16 03:47:26 -0500

Hi there,

It looks like you're assuming that the $awsbackupdetails var you set in server.pp will be available to your defined type, which isn't the case. A solution would be to explicity pass it as a param. create_resources has an optional third argument which allows you to pass in params, so you could do something like this in server.pp:

$defaults = {
  var => $awsbackupdetails,
}
create_resources('backupaws::duply', $awss3backup, $defaults)

Then get duply.pp to expect $var as a param:

define backupaws::duply($var) {
  ...
}
edit flag offensive delete link more

Comments

That's the danger of putting a define inside of your class, it looks like it should have 'local scope' for the variables, but that's not how it works in puppet.

DarylW gravatar imageDarylW ( 2016-06-15 20:07:32 -0500 )edit
0

answered 2016-06-16 00:36:00 -0500

Gabor gravatar image

Thanks for answer! This is a very interest, because one of the VMs wokring well this solution .... and I don't give this error.....

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-06-14 13:08:51 -0500

Seen: 106 times

Last updated: Jun 16 '16