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!

  • How to programmatically create a commit with Rugged?
  • Update of blog site via cron does not work
  • Automatic version in DATETIME format on every “git push” on Heroku or elsewhere
  • git post-receive hook not running bundle install
  • Ruby “bundle install” error on Openshift
  • Heroku: Run Rails Application with PHP Script?
  • RVM install 1.9.2-head ERROR
  • Rails deployment to staging using capistrano generates the following error
  • One Solution collect form web for “Chef passing revision variable to deploy resource”

    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
    
    Git Baby is a git and github fan, let's start git clone.