Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chef passing revision variable to deploy resource

I'm trying to pass the git branch that I want to deploy to the Chef deploy resource but it isn't working, I'm guessing it's because the resources are compiled separately and then just executed? But I might be wrong as my understanding of Ruby is limited.

So I'm trying to do this:

ruby_block 'revision' do
  block do
    # Some code determines the branch to be deployed
    branch = 'master'

    node.run_state['branch'] = branch

  end
end

deploy "#{node['path']['web']}" do
  action :deploy
  repository "#{node['git']['repository']}"
  revision "#{node.run_state['branch']}"
end

However the deploy resource doesn't get passed that variable.

Is this the correct way to go about this? Is there a better or other way?

Thanks in advance!

like image 634
mjphaynes Avatar asked Oct 22 '12 21:10

mjphaynes


1 Answers

At the moment chef compiles your deploy resource ruby_block resource is not run yet, so node.run_state['branch'] is not set. You have to move your deploy resource into ruby_block and define it dynamically.

ruby_block 'revision' do
  block do
    # Some code determines the branch to be deployed
    branch = 'master'

    node.run_state['branch'] = branch

    depl = Chef::Resource::Deploy.new node['path']['web'], run_context
    depl.repository node['git']['repository']
    depl.revision node.run_state['branch']
    depl.run_action :deploy
  end
end
like image 123
Draco Ater Avatar answered Nov 06 '22 15:11

Draco Ater