I am running a Chef 12 Opsworks stack and I created a custom cookbook to take some backups of a few folders on my webserver.
Maybe my approach to this is wrong, but I basically have two (or more) recipes for each website I want backed up and then I'm updating some attributes (site name, backup folder, etc) in each recipe.
So I start with the following in my default.rb file in the attributes folder:
default['backup']['site'] = "SITE1"
default['backup']['root'] = "/var/www/SITE1"
Then in each backup recipe I have the following at the top of the recipe followed by my back up code:
site1.rb
node.override['backup']['site'] = "SITE1"
node.override['backup']['root'] = "/var/www/SITE1"
site2.rb
node.override['backup']['site'] = "SITE2"
node.override['backup']['root'] = "/var/www/SITE2"
Now in my Setup step on the Opsworks Layer I add all the backup recipes, but the problem arises when I start an instance (or run the Setup step from the Deployments) because the attributes seem to be set to whatever the last recipe sets them in alphabetical order.
So SITE1 backup script for example will end up being built with the /var/www/SITE2
root folder in its config and thus not backing up the right site.
Is there are way to prevent this from happening? From what I gather (from my example and reading Chef docs) the attributes are all compiled together at the beginning and then the recipes are being run - which is why the last set of attributes gets set as the final version and then all recipes using those attributes will get those values.
The only way I can deploy them at the moment is by running each recipe independently thus using the correct attribute values, but the moment the instance gets rebooted or the Setup step is ran manually all backup scripts will go back to backing up just one site.
Is my approach to this wrong? Should I be creating separate named attributes for each recipe?