![](/img/trans.png)
[英]why chef_gem recipe works from chef-solo and not through vagrant
[英]Why last command in chef recipe executing first?
我在無業游民的centos-72 Chef 12.19.36中運行
在metadata.rb中depends 'rabbitmq', '~> 3.0'
我嘗試的run_list
"recipe[rabbitmq]",
"recipe[rabbitmq::mgmt_console]",
"recipe[rabbitmq::user_management]",
"recipe[mycookbook::myrecipe]"
我的食譜是
chef_gem 'rabbitmq_http_api_client' do
version '1.8.0'
action :install
end
require "rabbitmq/http/client"
endpoint = "http://127.0.0.1:15672"
client = RabbitMQ::HTTP::Client.new(endpoint, :username => "user", :password => "321")
client.declare_exchange("myvhost", "myexchange", durable: true, type: "direct")
沒有myrecipe,一切都會好的。 但是,如果我將myrecipe添加到運行列表的末尾,則其內容將在其余食譜之前開始運行,並且當然會出現Failed to open TCP connection to 127.0.0.1:15672 (Connection refused - connect(2) for "127.0.0.1" port 15672)
現在我用這段代碼解決了這個問題,但是我不喜歡這樣,也不理解為什么在Rabbitmq安裝之前運行clarify_exchange
include_recipe 'rabbitmq'
rabbitmq_plugin 'rabbitmq_management' do
action :enable
end
rabbitmq_user 'user' do
password "321"
action :add
end
rabbitmq_vhost 'myvhost' do
action :add
end
rabbitmq_user 'user' do
vhost 'myvhost'
permissions ".* .* .*"
action :set_permissions
end
rabbitmq_user 'user' do
tag 'administrator'
action :set_tags
end
rabbitmq_user "guest" do
action :delete
notifies :run, 'ruby_block[declare_rmq_exchange]'
end
chef_gem 'rabbitmq_http_api_client' do
version '1.8.0'
action :install
end
require "rabbitmq/http/client"
endpoint = "http://127.0.0.1:15672"
ruby_block 'declare_rmq_exchange' do
block do
client = RabbitMQ::HTTP::Client.new(endpoint, :username => "user", :password => "321")
client.declare_exchange("myvhost", "myexchange", durable: true, type: "direct")
end
action :nothing
end
這是由廚師-客戶兩階段模型引起的。 首先,執行ruby代碼( 編譯階段 ),然后執行已定義資源的實現(例如rabbitmq_user
或chef_gem
)( 收斂階段 )。
在編譯階段執行對RabbitMQ::HTTP::Client.new
調用時,將在用戶設置之前首先執行它。
將此代碼包裝在ruby_block
資源中,以便按預期順序執行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.