Bug #14797
"require => Exec" ignored when using template as content
| Status: | Accepted | Start date: | 06/04/2012 | |
|---|---|---|---|---|
| Priority: | High | Due date: | ||
| Assignee: | - | % Done: | 0% | |
| Category: | templates | |||
| Target version: | - | |||
| Affected Puppet version: | 2.7.11 | Branch: | ||
| Keywords: | puppet template exec file | |||
Description
Hi,
I’ve developped a function that might replace file based on template according to exec result :
Functions¶
define configtemplate ($template,$file,$condition) {
exec { "check_${file}_${condition}":
command => '/bin/true',
unless => "/bin/grep -qF '${condition}' '${file}'";
}
file { "$file":
path => $file,
content => template($template),
require => Exec["check_${file}_${condition}"],
}
}
Named : template if ip of server not present¶
configtemplate { "/etc/bind/named.conf":
template => "named/named.conf.erb",
file => "/tmp/named.conf",
condition => "$ipaddress",
}
The problem is that the function is not testing the result of exec. Therefore, file is pushed at every call.
debug: /Stage[other]/Other/Other::Configtemplate[/etc/bind/named.conf]/File[/tmp/named.conf]/content: Executing ‘diff -u /tmp/named.conf /tmp/puppet-file20120604-21313-xoww0p-0’
notice: /Stage[other]/Other/Other::Configtemplate[/etc/bind/named.conf]/File[/tmp/named.conf]/content:
—– /tmp/named.conf 2012-06-04 15:48:08.912408219 +0200
+++ /tmp/puppet-file20120604-21313-xoww0p-0 2012-06-04 15:50:33.415293057 +0200
@@ -170,11 +170,3 @@
// allow-notify {
//};¶
-zone “ataos-reprise.com” IN { – type master; – file “pri/ataos-reprise.com.zone”; – allow-update { none; }; – notify yes; – also-notify { 88.190.22.99; }; –};
debug: Finishing transaction 70329434276740 info: FileBucket got a duplicate file {md5}e46556933c2ac503aac5c66f315c40ee info: /Stage[other]/Other/Other::Configtemplate[/etc/bind/named.conf]/File[/tmp/named.conf]: Filebucketed /tmp/named.conf to puppet with sum e46556933c2ac503aac5c66f315c40ee notice: /Stage[other]/Other/Other::Configtemplate[/etc/bind/named.conf]/File[/tmp/named.conf]/content: content changed ‘{md5}e46556933c2ac503aac5c66f315c40ee’ to ‘{md5}0fbccf011bd90c028f703f15a40a96e2’ debug: /Stage[other]/Other/Other::Configtemplate[/etc/bind/named.conf]/File[/tmp/named.conf]: The container Other::Configtemplate[/etc/bind/named.conf] will propagate my refresh event
Related issues
History
#1
Updated by Pierre Grandin about 1 year ago
require doesn’t do what you expect : the exec will be done, before the file block, and the file block will be done too, whatever the result of the exec.
#2
Updated by Kelsey Hightower about 1 year ago
- Status changed from Unreviewed to Accepted
There are quite a few tickets around the behavior around this. I think we are at the point where we need to clearly define/verify the behavior when any resource requires an Exec resource.