def substitute(init, value, depth)
      if depth > VAR_SUBSTITUTION_MAX_DEPTH
        raise SystemStackError, "Maximal recursive depth (#{VAR_SUBSTITUTION_MAX_DEPTH})
          reached for resolving variable #{init}, reached #{value} before stopping."
      end
      original = value.clone
      value.gsub!(/(#(.*?)#)+?/) do
       # 1. Match pre-defined variable, or variable defined in appliance definition.
       next @appliance_config.variables[$2] if @appliance_config.variables.has_key?($2)
       # 2. Match from environment variables.
       next ENV[$2] unless ENV[$2].nil?
       # 3. No match, replace the original string.
       $1
      end
      substitute(init, value, depth+1) unless original == value
    end
def substitute(init, value, depth)
      if depth > VAR_SUBSTITUTION_MAX_DEPTH
        raise SystemStackError, "Maximal recursive depth (#{VAR_SUBSTITUTION_MAX_DEPTH})
          reached for resolving variable #{init}, reached #{value} before stopping."
      end
      original = value.clone
      value.gsub!(/(#(.*?)#)+?/) do
       # 1. Match pre-defined variable, or variable defined in appliance definition.
       next @appliance_config.variables[$2] if @appliance_config.variables.has_key?($2)
       # 2. Match from environment variables.
       next ENV[$2] unless ENV[$2].nil?
       # 3. No match, replace the original string.
       $1
      end
      substitute(init, value, depth+1) unless original == value
    end
Replace variables with values. This will occur recursively upto a limited
 depth if the resolved values themselves contain variables.