Template resource notifies looks not to work


#1

Hello,
if I am not mistaken a “template” resource can notify a “service” resource if it changes just using notifies in it.
I have this code:

service ‘sssd’ do
supports :restart => true
action :nothing
end

if node[‘platform_family’] == ‘rhel’ && node[‘platform’] == 'redhat’
so_version = node[‘platform_version’].match(/^(\d+)/)
if so_version[0] == “6” || so_version[0] == “7” then
directory ‘/etc/sssd’ do
owner 'root’
group 'root’
mode '0600’
action :create
end
template ‘/etc/sssd/sssd.conf’ do
source 'sssd.conf.erb’
owner 'root’
group 'root’
mode 0600
notifies :restart, ‘service[sssd]’, :immediate
end
end
end

I would expect that as soon as the file /etc/sssd/sssd.conf changes it would be reverted to the template source and the service sssd would be restarted.

However just the /etc/sssd/sssd.conf file is reverted to the template but the sssd service is not restarted.
What am I doing wrong?

Thank You

Regards

M.


#2

try that…

execute ‘service sssd restart’ do
command 'service sssd restart’
action :nothing
end

template ‘/etc/sssd/sssd.conf’ do
source 'sssd.conf.erb’
owner 'root’
group 'root’
mode "0600"
notifies :run, ‘execute[service sssd restart]’, :immediate
end


#3

Hi @mauog,

That looks correct. What does Chef log after it updates the template; do you see a log message about the notification?
If so, I’d recommend checking journald (in the RHEL 7 case) and seeing if anything obvious is there.

(you can also do node['platform_version'].to_i >= 6 rather than the match and check you have, but that’s not going to affect the chef run)

Cheers,
-Thom


#4

I did some test and I can say that nic_chef’s way works fine where mine did not.
It looks there is something I did not understand :slight_smile:
@nic_chef could you explain me why? :blush:

Thank You

M.


#5

@mauog - what Nic is doing skips all the management of services that Chef provides, and so is likely to lead to problems in future.

We’d really love to see the log output of a chef run with your code, so we can help you understand and fix, properly, the problem you’ve run in to.


#6

@thommay
I’ll be glad to help you.
Let me know what is the most convenient way to help you troubleshooting the issue.
Do you need the /var/log/chef/client.log only?
Should I attach it here or do you prefer using another way?

Mauro


#7

The easiest way, generally, is to create a gist with the output of running chef and with the recipe code that you’re attempting to run.