Skip to content
This repository was archived by the owner on Mar 12, 2019. It is now read-only.

Please add variable substitution #45

Open
wesparish opened this issue May 23, 2013 · 1 comment
Open

Please add variable substitution #45

wesparish opened this issue May 23, 2013 · 1 comment
Milestone

Comments

@wesparish
Copy link

It would be nice for Spiceweasel to have the ability to dynamically replace variables at runtime.

For example, it would be nice to be able to set a Spiceweasel variable "password" to "mysecret123" and use a replacement string throughout the rest of the manifest file. Furthermore, it would also be nice to have the ability to not only define key/value pairs for variables, but also to define key/special_value variables that allow prompting the user at runtime (eg: prompting for a sensitive password that cannot be stored in plaintext).

As a possible path to take (assuming 2 special strings, prompt_for_password (no echo) and prompt_for_text (echo)):

variables:
- root_password:
    value: "prompt_for_password"
- admin_user_name:
    value: "prompt_for_text"
- mray_pem_file:
    value: "~/.ssh/mray.pem"

nodes:
- serverA:
    run_list: role[base]
    options: -i <%= variables[:mray_pem_file] %> -x <%= variables[:admin_user_name] %> --sudo -P <%= variables[:root_password] %>
@rberger
Copy link
Contributor

rberger commented Jul 26, 2013

I just tested, that if you use the ruby style of spiceweasel configurations, you can do ruby stuff which includes effectively the things you are discussing (I didn't try prompting but I presume it would work)

For instance I wanted to set attributes inside of the spiceweasel config file and not in roles but I didn't want to embed json directly in the cluster option lines. So I did:

pod_attributes = {
  :pod => "default",
  :haproxy => {
    :balance_algorithm => "hdr(X-Real-IP)",
    :defaults_options => [
                          "httplog",
                          "dontlognull",
                          "forwardfor", 
                          "redispatch",
                          "httpchk GET /ui/"
                         ]
  }
}

and then in the related cluster section I used ruby string interpolation #{pod_attributes.to_json} to expand that out in the options . Note that the spiceweasel {{n}} mechanism for embedding the index of the instance still works too:

  "clusters"=>
  [
   {
     "qa"=>
     [
      {
        "ec2 1"=>
        {
          "run_list"=>"role[rm-pod] recipe[rm-pod] recipe[logstash::awesant]",
          "options"=>
          "-d chef-full  -S mykey -G qa -I ami-eb3c0183 -f m1.medium -j \'#{pod_attributes.to_json}\' -N qplb{{n}}.app
        }
      },
...

The main problem is if there is any syntax errors you get a rather meaningless error. I may get around to adding some stuff and do a pull request but probably not soon since I'm going to be away for a couple of weeks.

@mattray mattray added this to the 2.8 milestone Feb 19, 2014
@mattray mattray modified the milestones: 3.0, 2.8 Sep 16, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants