I wrote the a Chef cookbook which configures a server in the company.

One of the tasks there is to install an "apt_package" called "pssh" and another task is intended to be run after the pssh package installation takes place.

In reality, the second task is running before the package installation and then the chef-client run fails saying that the relevant file is missing - it is missing because the pssh package installation creates it.

I'm trying to configure the second task to run only after the package installation task is finished.

here's the relevant code:

apt_package 'pssh' do
  action :install
  subscribes :run, 'file[/usr/bin/pssh]', :before

file '/usr/bin/pssh' do
  owner 'root'
  group 'root'
  mode 0755
  content ::File.open("/usr/bin/parallel-ssh").read
  action :create

I've tried using both "notifies" and "subscribes" but to no avail, the second task always runs first and causes the chef-client run to fail.

How do I establish dependency between the tasks?


The issue is that the way you have things written, the file read happens at compile time. Check out https://coderanger.net/two-pass for details on to fix it, but briefly you need to use the lazy{} helper around the file read.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.