claranet / puppet-consul_template

A Puppet module to manage the config and jobs of Consul Template from Hashicorp
Apache License 2.0
30 stars 89 forks source link

Environment Variables in Startup Scripts #53

Closed ccampanale closed 8 years ago

ccampanale commented 8 years ago

I'm currently working on a project that requires that I use an environment variables in my CT template to determine which configuration to pull. I discovered that what is preventing this from working is the lack of these environment variables when CT is running as a daemon. (When ran manually it uses my running environment and pulls the variables just fine, just not as a daemon.)

My question is, would it be possible to add a parameter to the class/module for supplying the startup scripts with additional environment variables? This would be especially helpful as I would be able to supply this in hiera from facts and would simplify a lot of work on my end!

Also, if I sound wildly insane asking this, please feel free to enlighten me on how to accomplish what I am attempting to do. I'm not a seasoned linux vet and still have lots to learn. :)

Thanks!

ccampanale commented 8 years ago

I ended up using the same trick from my other issue (#54) to get something working, though this is somewhat clunky:

consul_template::extra_options: |
  '-template /path/to/my/template.ctmpl:/path/to/my/output.out'
  export FACT=%{::myfact}

It works (the daemon now sees the envvar), but it's not pretty so support for this would be highly appreciated! :) (If I have time even I will clone/edit/pr this change... )

gdhbashton commented 8 years ago

Hi,

Thanks for in the insight into your use case - I'm pleased that you found a way to squeeze data in through extra_options as I'm currently not minded to incorporate support for env variables into the module since it'll mean updating all the different init scripts.

Always happy to receive a PR for such things, of course :) I'll close this for now.

ccampanale commented 8 years ago

I understand! I may be able to work on this and submit a PR for you. My concern would be my ability to test outside of the sysv and systemd templates but we'll see!

Thanks again!