[chef] Re: :delayed command invocation


Chronological Thread 
  • From: Thom May < >
  • To:
  • Subject: [chef] Re: :delayed command invocation
  • Date: Tue, 10 Apr 2012 16:05:13 +0100

2012/4/10 Motiejus Jakštys 
< >:
> Hi List,
>
> this was asked in IRC, nothing there, trying here now.
>
> Consider the following extract from the recipe:
>
> search(:users, 'groups:sysadmin') do |u|
>  execute "delete password" do
>    command "passwd -d #{u['id']}"
>    only_if { "test $(passwd -S #{u['id']} | awk '{print $2}') = L" }
>  end
>
>  user u['id'] do
>    uid u['uid']
>    ...
>    notifies :run, "execute[delete password]", :delayed
>  end
> end
>
> I want to run "passwd -d username" *after* the user is created.
>

your:
> execute "delete password" do
>    command "passwd -d #{u['id']}"
>    only_if { "test $(passwd -S #{u['id']} | awk '{print $2}') = L" }
>  end
>
should be:

execute "delete password" do
  command "passwd -d #{u['id']}"
  only_if { "test $(passwd -S #{u['id']} | awk '{print $2}') = L" }
  action :nothing
end

and then it'll only run once notified.
-Thom



Archive powered by MHonArc 2.6.16.

§