-
-
Save sawanoboly/6270602 to your computer and use it in GitHub Desktop.
Chefのレシピでsed的な事を実施 ref: http://qiita.com/sawanoboly/items/355288c4592bdf4a3550
This file contains hidden or 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
file './tmp1' do | |
_file = Chef::Util::FileEdit.new(path) | |
_file.search_file_replace_line('^hoge', "piyopiyo\n") | |
content _file.send(:contents).join | |
end | |
file './tmp2' do | |
_file = Chef::Util::FileEdit.new(path) | |
_file.search_file_replace('ge', "ga") | |
content _file.send(:contents).join | |
end |
This file contains hidden or 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
## 11.12.0以降のクライアント | |
file './tmp1' do | |
_file = Chef::Util::FileEdit.new(path) | |
_file.search_file_replace_line('^hoge', "piyopiyo\n") | |
content _file.send(:editor).lines.join | |
end | |
file './tmp2' do | |
_file = Chef::Util::FileEdit.new(path) | |
_file.search_file_replace('ge', "ga") | |
content _file.send(:editor).lines.join | |
end |
This file contains hidden or 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
pry(main)> Chef::Util::FileEdit.instance_methods(false) | |
=> [:search_file_replace_line, | |
:search_file_replace, | |
:search_file_delete_line, | |
:search_file_delete, | |
:insert_line_after_match, | |
:insert_line_if_no_match, | |
:write_file] |
This file contains hidden or 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
$ chef-apply appry.rb | |
Recipe: (chef-apply cookbook)::(chef-apply recipe) | |
* file[./tmp1] action create | |
- update content in file ./tmp1 from 639ed8 to 55d5ca | |
--- ./tmp1 2013-08-20 00:45:11.000000000 +0900 | |
+++ /var/folders/s9/kwcs_8ln0d32v_n4hdfb7td00000gn/T/.tmp120130820-24938-1bwvf6g 2013-08-20 00:45:41.000000000 +0900 | |
@@ -1,2 +1,2 @@ | |
-hogehoge | |
+piyopiyo | |
mogemoge | |
* file[./tmp2] action create | |
- update content in file ./tmp2 from 639ed8 to 93260c | |
--- ./tmp2 2013-08-20 00:45:03.000000000 +0900 | |
+++ /var/folders/s9/kwcs_8ln0d32v_n4hdfb7td00000gn/T/.tmp220130820-24938-h5bq4k 2013-08-20 00:45:41.000000000 +0900 | |
@@ -1,2 +1,2 @@ | |
-hogehoge | |
-mogemoge | |
+hogahoga | |
+mogamoga |
This file contains hidden or 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
$ chef-apply appry.rb -w | |
Recipe: (chef-apply cookbook)::(chef-apply recipe) | |
* file[./tmp1] action create | |
- Would update content in file ./tmp1 from 639ed8 to 55d5ca | |
--- ./tmp1 2013-08-20 00:45:11.000000000 +0900 | |
+++ /var/folders/s9/kwcs_8ln0d32v_n4hdfb7td00000gn/T/.tmp120130820-24879-gemfn5 2013-08-20 00:45:19.000000000 +0900 | |
@@ -1,2 +1,2 @@ | |
-hogehoge | |
+piyopiyo | |
mogemoge | |
* file[./tmp2] action create | |
- Would update content in file ./tmp2 from 639ed8 to 93260c | |
--- ./tmp2 2013-08-20 00:45:03.000000000 +0900 | |
+++ /var/folders/s9/kwcs_8ln0d32v_n4hdfb7td00000gn/T/.tmp220130820-24879-ieq0kc 2013-08-20 00:45:19.000000000 +0900 | |
@@ -1,2 +1,2 @@ | |
-hogehoge | |
-mogemoge | |
+hogahoga | |
+mogamoga |
This file contains hidden or 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
$ chef-apply appry.rb | |
Recipe: (chef-apply cookbook)::(chef-apply recipe) | |
* file[./tmp1] action create (up to date) | |
* file[./tmp2] action create (up to date) |
This file contains hidden or 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
pry(main)> Chef::Util::FileEdit.instance_methods(false) | |
=> [:search_file_replace_line, | |
:search_file_replace, | |
:search_file_delete_line, | |
:search_file_delete, | |
:insert_line_after_match, | |
:insert_line_if_no_match, | |
:write_file] |
This file contains hidden or 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
clock = Chef::Util::FileEdit.new("/etc/sysconfig/clock") | |
clock.search_file_replace_line(/^ZONE=.*$/, "ZONE=\"#{node[:tz]}\"") | |
clock.write_file |
This file contains hidden or 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
hogehoge | |
mogemoge |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment