:delayed command invocation

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.

However, this is what happens:

[Tue, 10 Apr 2012 14:55:39 +0100] INFO: Processing execute[delete password]
action run (users::sysadmins line 41)
[Tue, 10 Apr 2012 14:55:39 +0100] INFO: execute[delete password] sh(passwd -d
motiejus)
passwd: password expiry information changed.
[Tue, 10 Apr 2012 14:55:39 +0100] INFO: execute[delete password] ran
successfully
[Tue, 10 Apr 2012 14:55:39 +0100] INFO: Processing user[motiejus] action create
(users::sysadmins line 47)

I suspect this happens because user do end block is added to :delayed execution
queue once it’s finished… [delete password] is added before that. Any way to
work this around? Or should I write the recipe entirely differently? I am very
open to suggestions.

Thanks,
Motiejus

2012/4/10 Motiejus Jakštys desired.mta@gmail.com:

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

On Tue, Apr 10, 2012 at 18:05, Thom May thom@clearairturbulence.org wrote:

2012/4/10 Motiejus Jakštys desired.mta@gmail.com:
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

Thanks. My [copy of the] cookbook is complete!

--
Motiejus Jakštys