We are firmly told not to use Notepad.exe for editing… so we’ll use Notepad++… as we would anyway, most likely.
I have a file [create_users.rb], containing this:
Which says: the resource type is [file], the resource name is [d:\create_users.txt]. As no [action] is specified, I’ll do the default action for a [file], which is [create]. And the file’s content is to be [Dennis].
This is the command line:
, and the run, including the content of the generated file:
So the .rb file specified a simple Desired State, i.e. create the file, give it some content. What happens if we edit the content file, and re-run the rb file?
The file has been overwritten based on the Desired State rules:
If we now revert the current content back to the manual edit:
, and update the rb file to remove the content rule…
, and re-run the Chef command:
, then because we only asked it to ensure that the file was created (default), then the content remains as-is, and when I move the focus back to Notepad++, I do not get a prompt to say the file has been changed/reloaded. This is probably because Resources use the Test/Repair pattern: Test to see if the resource is in the Desired State. If No, Repair, else return.
There is good documentation on the File Resource here. Getting access rights often feels like the trickiest challenge, so it will be interesting to see how Chef can facilitate that… not needed right now.