在厨师食谱中使用gsub方法时出错

问题描述 投票:0回答:1

我是厨师新手,对Ruby几乎一无所知。

我的存储值低于'storage_conn_str'

SAS令牌:#Chef :: DelayedEvaluator:0x0000000006e28c80 @ c:/ chef / cache / cookbooks / ***** / recipes / *****。rb:20

在我的食谱中,我用'&'代替'&'。我已经使用lazy延迟了ruby块和资源中变量的执行。

下面是我的食谱

key_vault_name node['key_vault_names']['Test']
end

ruby_block 'modify_token' do
  block do
    sastoken = lazy { node.run_state['SAS_Token'] }
    Chef::Log.info("SAS Token: #{sastoken}")
    modified_token = lazy { sastoken.gsub(/[&]/, '&') }
    Chef::Log.info("SAS Token after replacement: #{modified_token}")
    storage_conn_str = lazy { File.join(storage_conn_str , modified_token)}
    Chef::Log.info("storage connection string: #{storage_conn_str}")
  end
  action :run
end

webapp 'TableStorageAPI' do
source URI.join(node['binary_storage_uri'], app_node['source']).to_s
version app_version
appPoolName 'TableStorageAPI'
path '/V1/TableStorageAPI'
siteName 'SSL'
enable32Bit false
pipeline_mode :Integrated
use_servicebroker false
transform_variables(
storage_conn: lazy {storage_conn_str},
mail_to: app_node['mail_to'],
mail_from: app_node['mail_from'],
smtp_host: node['tps']['smtp']['server'],
log_location: app_node['log_location'],
env_name: app_node['env_name']
)
end```
----------------------------------------------
I am not sure why webapp resource is executing before the computation of 'storage_conn_str'.
ruby chef chef-recipe
1个回答
0
投票

“我不确定为什么在计算'storage_conn_str'之前Webapp资源正在执行。”

这是因为storage_conn_str是在ruby_block'modify_token'中定义的。 Webapp资源不可见。

您可以做的是,创建一个属性。

例如:node [“ mycb”] [“ storage_conn_str”] =“”

在ruby_block中

ruby_block 'modify_token' do
  block do
    ...
    storage_conn_str = lazy { File.join(storage_conn_str , modified_token)}
    Chef::Log.info("storage connection string: #{storage_conn_str}")
    node.default["mycb"]["storage_conn_str"] = storage_conn_str 
  end
  action :run
end

在webapp资源中]
webapp 'TableStorageAPI' do
...
   storage_conn: node["mycb"]["storage_conn_str"]
...
end

这应该可以解决您遇到的问题

© www.soinside.com 2019 - 2024. All rights reserved.