Created
March 29, 2015 18:53
-
-
Save noahlz/9fafbeec2d86c5fd65fe to your computer and use it in GitHub Desktop.
Learning Chef FileEdit (based on https://learn.chef.io/learn-the-basics/ubuntu/configure-a-resource/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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