Chef - using flag files to control recipe runs


I’m using Chef Server 12, Windows Server 2012R2 nodes.

I’m automating an off the shelf product that can only be installed in distinct separate stages.

  1. Install base files and install first application then create a user account manually through a GUI.
  2. Install application with configs referencing account from step 1 to a certain level that then generates SQL scripts
  3. Once those scripts are installed and tested continue with next part of deployment.

Currently I’d using at the beginning of a wrapper recipe an if statement to allow it to proceed.

if node.chef_environment == ‘xxx’ and node[‘application’][‘admin_details_created’] == ‘true’ and node[‘application’][‘SQL_DBs_Created’]== ‘true’

But this means attributes needs updating and uploading to chef server after each portion.

I’d like to have flag files that are changed locally so the attributes etc never change. Then teams can deploy the application stack and control simply deleting / changing flag files.

Then I can delete each file once task done and if those dont exist the recipe executes.

If i use Chef to create the files, chef is idompoent and will recreate the files when changed / deleted.

How can i use chef to create the files as one off processes.

Is it basically, create files, create a log file for the file creation process then add an not_if to check that log file exists?

Many thanks for anyone that can help.


This sounds like a good use case for guards. While chef likes to be idempotent, you have a pretty large degree of control there with guards as to whether a resource runs or not via only_if and not_if. Related, attributes don’t need to be uploaded each time as the recipe itself could set an attribute at the normal level (node.set) which would persist to the next run and could be used to inform where in the process the node is so that the recipe may take the appropriate action.

I’d give guards a shot and see if you can model it that way.

Hi Seth,

many thanks for your response and will look into using guards and node.set to see if I can get those to work for this situation.