Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
## Simple extension of the Chef tutorial for appending line(s) to the end of a cookbook
## Alternative to copying an entire cookbook just to add one line to a config file.
## (Apparently, partials are an alternative in Chef 11?
## http://stackoverflow.com/a/19167106/7507
file 'motd' do
content "hello chef\n"
end
ruby_block "ensure sig to end of file" do
block do
fe = Chef::Util::FileEdit.new("motd")
fe.insert_line_if_no_match(/@noahlz/, "@noahlz was here")
fe.write_file
end
end
[nzucker: motd]$ echo "hello chef" > motd
[nzucker: motd]$ cat motd
hello chef
[nzucker: motd]$ sudo chef-apply hello.rb
Recipe: (chef-apply cookbook)::(chef-apply recipe)
* file[motd] action create (up to date)
* ruby_block[ensure sig to end of file] action run
- execute the ruby block ensure sig to end of file
[nzucker: motd]$ cat motd
hello chef
@noahlz was here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment