Created
September 15, 2014 17:23
-
-
Save denniswalker/bc6600cca8aa57885816 to your computer and use it in GitHub Desktop.
chef ultisnips
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
snippet file "Chef File Resource" | |
file '$1' do | |
action :create | |
owner '${2:root}' | |
group '${3:root}' | |
mode '${4:0644}' | |
end | |
endsnippet | |
snippet directory "Chef - Directory resource" | |
directory '${1: dirname}' do | |
action :create | |
owner '${3:root}' | |
group '${4:root}' | |
mode '${5:0755}' | |
recursive true | |
end | |
endsnippet | |
snippet packages "Chef - install packages" | |
%w( | |
${1:package_name} | |
).each do |pkg| | |
package pkg | |
action :install | |
end | |
end | |
endsnippet | |
snippet packageo "Chef - package with options" | |
package '${1:package_name}' do | |
action :install | |
version '${2:version}' | |
options '${3}' | |
end | |
endsnippet | |
snippet ruby_block "Chef - Ruby Block" | |
ruby_block '${1:name}' do | |
block do | |
${2:ruby code} | |
end | |
end | |
endsnippet | |
snippet search_file_replace "Chef - Search in files and replace" | |
%w(${1:files}).each do |cfg| | |
ruby_block "Change ${2:text_to_replace} in #{cfg} ${3:replacement_text}" do | |
block do | |
f = Chef::Util::FileEdit.new(File.join('${4:parent_dir}', cfg)) | |
f.search_file_replace(/${2:text_to_replace}/, "${3:replacement_text}") | |
f.write_file | |
end | |
end | |
end | |
endsnippet | |
snippet cblock "Chef - Config Block" | |
okl_data_config_block '${1:file}' do | |
uuid '${6:`uuidgen`}' | |
block <<-EOS.gsub(/^\s+/, '') | |
${2:stuff to add} | |
EOS | |
owner '${3:root}' | |
group '${4:root}' | |
mode ${5:0644} | |
end | |
endsnippet | |
snippet user "Chef - User resource" | |
user '${1:user}' do | |
action :create | |
comment '${2:comment}' | |
uid 1000 | |
gid 'users' | |
home '/home/${1:user}' | |
shell '/bin/bash' | |
password "$1$JJsvHslV$szsCjVEroftprNn4JHtDi." | |
supports manage_home: true | |
end | |
endsnippet | |
snippet bash "Chef - Bash Resource" | |
bash '${1:Install Something}' do | |
user '${2:root}' | |
cwd '${3:/tmp}' | |
code <<-EOH.gsub(/^\s+/, '') | |
${4:code} | |
EOH | |
creates '${5:file}' | |
end | |
endsnippet | |
snippet only_if "Chef - Only if condition" | |
only_if { ${1:File.exist?('')} } | |
endsnippet | |
snippet not_if "Chef - not if condition" | |
not_if { ${1:File.exist?('')} } | |
endsnippet | |
snippet include_recipe "Chef include_recipe" | |
include_recipe "#{cookbook_name}::${1:recipe}" | |
endsnippet | |
snippet notifiesi "Chef - notifies resource" | |
notifies :restart, 'service[name]', :immediately | |
endsnippet | |
snippet service "Chef - service resource" | |
service '${1:service name}' do | |
pattern '${2:.*something.*}' | |
supports status: true, start: true, restart: true, stop: true | |
action [:enable, :start] | |
end | |
endsnippet | |
snippet template "Chef - template resource" | |
template '${1:name of file}' do | |
source '${1:name of file}.erb' | |
owner '${2:root}' | |
group '${3:root}' | |
mode '${4:0644}' | |
variables( ${5:config: node[:config][:config_var]} ) | |
end | |
endsnippet | |
snippet remote_file "Chef - remote_file resource" | |
remote_file '${1:/tmp/remote_file}' do | |
action :create | |
owner '${2:root}' | |
group '${3:root}' | |
mode '${4:0644}' | |
source '${5:http://}' | |
checksum '${6:sha}' | |
end | |
endsnippet | |
snippet cookbook_file "Chef - cookbook_file resources" | |
cookbook_file '${1:name of file}' do | |
action :create | |
path '${2:path to file}' | |
source '${3:which cookbook}' | |
owner '${4:root}' | |
group '${5:root}' | |
mode '${6:0644}' | |
cookbook '${7:cookbook}' | |
end | |
endsnippet | |
snippet encoding "top of all ruby files" | |
encoding: utf-8 | |
endsnippet |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment