-
Notifications
You must be signed in to change notification settings - Fork 117
Description
PROBLEM
If ${postfixdir}/${title}.db is deleted after it has been created, it will never be created again, unless ${postfixdir}/${title} is refreshed.
There's also another scenario where a .db won't ever be created. For example:
- puppet creates
/etc/postfix/sasl_passwdand schedules exec/usr/sbin/postmap /etc/postfix/sasl_passwd - lots of other puppet code run
- puppet finally runs exec
/usr/sbin/postmap /etc/postfix/sasl_passwdand createssasl_passwd.db
If puppet fails on step 2 above, then the .db file will never be created.
Exemple of problem:
# cat test.pp
node default {
file { "/tmp/file1":
ensure => present,
content => "test\n",
}
exec { "/tmp/file2":
command => "/bin/cat /tmp/file1 > /tmp/file2",
subscribe => File["/tmp/file1"],
refreshonly => true,
}
}
# puppet apply test.pp
Notice: Compiled catalog for myserver in environment production in 0.61 seconds
Notice: /Stage[main]/Main/Node[default]/File[/tmp/file1]/ensure: created
Notice: /Stage[main]/Main/Node[default]/Exec[/tmp/file2]: Triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.33 seconds
# rm -f file2
# puppet apply test.pp
Notice: Compiled catalog for myserver in environment production in 0.49 seconds
Notice: Finished catalog run in 0.27 seconds
SOLUTION
Remove refreshonly => true, and add creates => "${postfixdir}/${title}.db",
TEST SCRIPT
# cat test.pp
node default {
file { "/tmp/file1":
ensure => present,
content => "test\n",
}
exec { "/tmp/file2":
command => "/bin/cat /tmp/file1 > /tmp/file2",
subscribe => File["/tmp/file1"],
creates => "/tmp/file2",
}
}
TEST 1
scenario: Initial puppet run. None of the files exist
Expected result: Both files are created
# puppet apply test.pp
Notice: Compiled catalog for myserver in environment production in 0.53 seconds
Notice: /Stage[main]/Main/Node[default]/File[/tmp/file1]/ensure: created
Notice: /Stage[main]/Main/Node[default]/Exec[/tmp/file2]/returns: executed successfully
Notice: /Stage[main]/Main/Node[default]/Exec[/tmp/file2]: Triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.33 seconds
# ls -l
total 12
-rw-r--r--. 1 root root 5 Apr 4 13:18 file1
-rw-r--r--. 1 root root 5 Apr 4 13:18 file2
-rw-r--r--. 1 lburiola lburiola 250 Apr 4 13:17 test.pp
# cat file1 file2
test
test
TEST 2
scenario: Second puppet run. Both files already exist
Expected result: Nothing happens
# puppet apply test.pp
Notice: Compiled catalog for myserver in environment production in 0.52 seconds
Notice: Finished catalog run in 0.28 seconds
TEST 3
scenario: file1 needs to be modified. file2 already on disk
expected result: file1 is modified. file2 is recreated
# echo foo > file1
# puppet apply test.pp
Notice: Compiled catalog for myserver in environment production in 0.52 seconds
Notice: /Stage[main]/Main/Node[default]/File[/tmp/file1]/content: content changed '{md5}d3b07384d113edec49eaa6238ad5ff00' to '{md5}d8e8fca2dc0f896fd7cb4cb0031ba249'
Notice: /Stage[main]/Main/Node[default]/Exec[/tmp/file2]: Triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.29 seconds
TEST 4
scenario: file1 exists. file2 doesn't exist.
expected result: file2 is created
# rm -f file2
# puppet apply test.pp
Notice: Compiled catalog for myserver in environment production in 0.55 seconds
Notice: /Stage[main]/Main/Node[default]/Exec[/tmp/file2]/returns: executed successfully
Notice: Finished catalog run in 0.30 seconds