Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More reliable way to manage ${postfixdir}/${title}.db files #113

Open
gburiola opened this issue Apr 4, 2017 · 1 comment
Open

More reliable way to manage ${postfixdir}/${title}.db files #113

gburiola opened this issue Apr 4, 2017 · 1 comment

Comments

@gburiola
Copy link

gburiola commented Apr 4, 2017

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:

  1. puppet creates /etc/postfix/sasl_passwd and schedules exec /usr/sbin/postmap /etc/postfix/sasl_passwd
  2. lots of other puppet code run
  3. puppet finally runs exec /usr/sbin/postmap /etc/postfix/sasl_passwd and creates sasl_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
gburiola pushed a commit to gburiola/puppet-postfix that referenced this issue Apr 4, 2017
@gburiola
Copy link
Author

gburiola commented Apr 4, 2017

Fixed on #114

gburiola pushed a commit to gburiola/puppet-postfix that referenced this issue Apr 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant