Skip to content

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

@gburiola

Description

@gburiola

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions