Using the Modified Postfix Cookbook - nshenry03/chef-repo GitHub Wiki

Before we can use the Postfix cookbook that we modified, we need to tag the release. First, get the current version of the cookbook from the metadata.rb file, then use git to create the tag:

git tag "2.1.7" -m "Tagging 2.1.7"
git push origin 2.1.7

NOTE: If you want to 'sign' the tag, you can do so with the '-s' flag; you'll simply want to let git know about your key using this command: git config --global user.signingkey <<Your Key's ID>>

Now all we have to do is add the following to you Cheffile:

cookbook 'postfix',
   :git => 'https://github.com/nshenry03/postfix',
   :ref => '2.1.7'

Then you can download your cookbook and upload it to the chef server:

librarian-chef install
knife cookbook upload postfix

Now we need to let all of our environments know about the new cookbook:

for env in $(ls environments/*.rb); do
  echo 'cookbook "postfix", "2.1.7"' >> ${env}
  knife environment from file ${env}
done

Then, modify roles/base.rb to look like this:

name 'base'
description 'Role applied to all servers'
env_run_lists 'production' => ['recipe[base-logic]', 'recipe[postfix::sasl_auth]', 'recipe[ntp]', 'recipe[timezone-ii]'],
                 'staging' => ['recipe[base-logic]', 'recipe[postfix::sasl_auth]', 'recipe[ntp]', 'recipe[timezone-ii]'],
                    'test' => ['recipe[base-logic]', 'recipe[postfix::sasl_auth]', 'recipe[ntp]', 'recipe[timezone-ii]'],
             'development' => ['recipe[base-logic]',                               'recipe[ntp]', 'recipe[timezone-ii]'],
                '_default' => ['recipe[base-logic]',                               'recipe[ntp]', 'recipe[timezone-ii]']
default_attributes(
  'ntp' => {
    'servers' => ['0.pool.ntp.org', '1.pool.ntp.org', '2.pool.ntp.org', '3.pool.ntp.org']
  },
  'timezone-ii' => {
    'tz' => 'UTC'
  }
)
override_attributes(
  'postfix' => {
    'smtp_sasl_auth_enable'      => 'yes',
    'smtp_tls_security_level'    => 'may',
    'relayhost'                  => '[smtp.sendgrid.net]:587'
  }
)

Finally, upload this role to the chef server:

knife role from file roles/base.rb

Finally you should be able to test this cookbook by starting up a server (vagrant up <<VM NAME>>) and bootstrapping it:

knife bootstrap localhost --ssh-user vagrant --ssh-password vagrant --ssh-port 2222 --run-list 'role[base]' --sudo --environment test --secret-file .chef/encrypted_data_bag_secret

NOTICE: I changed the environment to test instead of the default environment or the development environment... You can test with --environment development and see that postfix is NOT installed/configured.

⚠️ **GitHub.com Fallback** ⚠️