Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Services variable not working with hiera hash. Expects an array of hashes it seems. #230

Closed
brahama opened this issue Feb 22, 2016 · 6 comments

Comments

@brahama
Copy link

brahama commented Feb 22, 2016

Hi guys,

I am trying to make the hash for services work but i see in the conf json, that the result config is like this:

"services":{"http-pub":{"id":"vhost80","name":"http-pub","port":80},"http-pub443":{"id":"vhost443","name":"http-pub","port":443}}"services":{"http-pub":{"id":"vhost80","name":"http-pub","port":80},"http-pub443":{"id":"vhost443","name":"http-pub","port":443}}

when it shouhld be like this:

"services": [
        {"id":"vhost80","port":80, "name": "http-pub"},{"name":"http-pub","id":"vhost443","port":443}],

Or am i doing somethign wrong?

My hiera conf is like this:

my_profile::services" : { "http-pub":{ "name":"http-pub", "port":80, "id": "vhost80"},"http-pub443":{ "name": "http-pub", "port":443, "id":"vhost443"}},

Cheers!

@solarkennedy
Copy link
Contributor

The services entrypoint in puppet-consul just uses create_resources. It is not intended to map directly into consul json.

On the config on disk, I would expect to manifest as different files per service.

Your input to puppet consul is a hash, there the keys are the service names and the values are the inputs to consul::service.

consul::services: 
 "http-pub":    {"port":80, "id":"vhost80"}
 "http-pub443": {"port":443,"id":"vhost443"}

@brahama
Copy link
Author

brahama commented Feb 26, 2016

Hey! thanks for the response... right now i hve it like you mention. But that involves calling specifically the entrypoint for that services... I want to use hiera so i dont need to call that specifically in the module. I am trying to use the services variable that says it needs a hash. Sorry, im kinda new so maybe i didnt explained correctly...

validate_hash($services)

So in hiera i have to fill the variable like its a list then?

Cheers!

@bflad
Copy link

bflad commented Feb 26, 2016

Hi! As Kyle mentioned, and gave an example. The way the hiera is setup requires a pattern that translates into:

resource-title:
  resource-attribute1: value1
  resource-attribute2: value2

So for example in our production hiera, we have a setup like:

consul::services:
  service1:
    address: "%{::ipaddress}"
    checks:
      - http: http://localhost:29536/status
        interval: 5s
    port: 29536
    tags:
      - "asg:%{::asg}"
      - "datacenter:%{::datacenter}"
      - "ec2_placement_availability_zone:%{::ec2_placement_availability_zone}"
      - "server_role:%{::server_role}"
  service2:
    address: "%{::ipaddress}"
    checks:
      - http: http://localhost:8857/status
        interval: 5s
    port: 8857
    tags:
      - "asg:%{::asg}"
      - "datacenter:%{::datacenter}"
      - "ec2_placement_availability_zone:%{::ec2_placement_availability_zone}"
      - "server_role:%{::server_role}"

Of course your services and checks will be unique compared to my example, but generally this is how hiera works with create_resources() calls under the hood, like how its used in this module. Hope this helps!

@solarkennedy
Copy link
Contributor

Thanks @bflad, it is nice to see a more realistic example. I've added it to the README.

@brahama
Copy link
Author

brahama commented Mar 8, 2016

Ok! thanks for the responses guys. Very helpful.

@hopperd
Copy link
Contributor

hopperd commented Mar 25, 2016

I think this issue is resolved now, if not please re-open.

@hopperd hopperd closed this as completed Mar 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants