From c5d33c1298834ce40b8fbf344f281045771b5371 Mon Sep 17 00:00:00 2001 From: Ezra Zygmuntowicz Date: Wed, 8 Oct 2008 14:19:52 -0700 Subject: big refactor of the repo layout. move to a chef gem and a chef-server gem all with proper deps --- chef/examples/config.rb | 20 +++ chef/examples/config/chef-solo.rb | 11 ++ .../config/cookbooks/fakefile/attributes/first.rb | 2 + .../config/cookbooks/fakefile/definitions/test.rb | 13 ++ .../default/remote_test/another/turn/the_page.txt | 1 + .../files/default/remote_test/another/window.txt | 1 + .../fakefile/files/default/remote_test/mycat.txt | 1 + .../cookbooks/fakefile/files/default/the_park.txt | 3 + .../config/cookbooks/fakefile/recipes/default.rb | 151 +++++++++++++++++++++ .../fakefile/templates/default/monkey.erb | 5 + .../cookbooks/rubygems_server/attributes/first.rb | 1 + .../files/default/packages/net-scp-1.0.1.gem | Bin 0 -> 25600 bytes .../files/default/packages/net-sftp-2.0.1.gem | Bin 0 -> 61440 bytes .../files/default/packages/net-ssh-2.0.3.gem | Bin 0 -> 117248 bytes .../default/packages/net-ssh-gateway-1.0.0.gem | Bin 0 -> 18432 bytes .../cookbooks/rubygems_server/recipes/default.rb | 8 ++ .../cookbooks/servicetest/recipes/default.rb | 12 ++ .../config/cookbooks/tempfile/attributes/second.rb | 1 + .../config/cookbooks/tempfile/recipes/default.rb | 24 ++++ chef/examples/config/nodes/adam.rb | 14 ++ chef/examples/config/nodes/default.rb | 9 ++ chef/examples/config/nodes/junglist.gen.nz.rb | 14 ++ chef/examples/config/nodes/latte.rb | 14 ++ chef/examples/mrepo/Rakefile | 0 chef/examples/node.rb | 17 +++ chef/examples/node.yml | 134 ++++++++++++++++++ chef/examples/sample_definition.rb | 82 +++++++++++ chef/examples/sample_recipe.rb | 77 +++++++++++ chef/examples/search_index/segments | Bin 0 -> 16 bytes chef/examples/search_index/segments_0 | Bin 0 -> 25 bytes chef/examples/search_syntax.rb | 10 ++ chef/examples/user_index.pl | 115 ++++++++++++++++ chef/examples/user_index.rb | 27 ++++ 33 files changed, 767 insertions(+) create mode 100644 chef/examples/config.rb create mode 100644 chef/examples/config/chef-solo.rb create mode 100644 chef/examples/config/cookbooks/fakefile/attributes/first.rb create mode 100644 chef/examples/config/cookbooks/fakefile/definitions/test.rb create mode 100644 chef/examples/config/cookbooks/fakefile/files/default/remote_test/another/turn/the_page.txt create mode 100644 chef/examples/config/cookbooks/fakefile/files/default/remote_test/another/window.txt create mode 100644 chef/examples/config/cookbooks/fakefile/files/default/remote_test/mycat.txt create mode 100644 chef/examples/config/cookbooks/fakefile/files/default/the_park.txt create mode 100644 chef/examples/config/cookbooks/fakefile/recipes/default.rb create mode 100644 chef/examples/config/cookbooks/fakefile/templates/default/monkey.erb create mode 100644 chef/examples/config/cookbooks/rubygems_server/attributes/first.rb create mode 100644 chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-scp-1.0.1.gem create mode 100644 chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-sftp-2.0.1.gem create mode 100644 chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-ssh-2.0.3.gem create mode 100644 chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-ssh-gateway-1.0.0.gem create mode 100644 chef/examples/config/cookbooks/rubygems_server/recipes/default.rb create mode 100644 chef/examples/config/cookbooks/servicetest/recipes/default.rb create mode 100644 chef/examples/config/cookbooks/tempfile/attributes/second.rb create mode 100644 chef/examples/config/cookbooks/tempfile/recipes/default.rb create mode 100644 chef/examples/config/nodes/adam.rb create mode 100644 chef/examples/config/nodes/default.rb create mode 100644 chef/examples/config/nodes/junglist.gen.nz.rb create mode 100644 chef/examples/config/nodes/latte.rb create mode 100644 chef/examples/mrepo/Rakefile create mode 100644 chef/examples/node.rb create mode 100644 chef/examples/node.yml create mode 100644 chef/examples/sample_definition.rb create mode 100644 chef/examples/sample_recipe.rb create mode 100644 chef/examples/search_index/segments create mode 100644 chef/examples/search_index/segments_0 create mode 100644 chef/examples/search_syntax.rb create mode 100755 chef/examples/user_index.pl create mode 100755 chef/examples/user_index.rb (limited to 'chef/examples') diff --git a/chef/examples/config.rb b/chef/examples/config.rb new file mode 100644 index 0000000000..171554c416 --- /dev/null +++ b/chef/examples/config.rb @@ -0,0 +1,20 @@ +# +# Example config +# + +nodes_from([ + Chef::Node::YAML => { + :search_path => [ "/etc/chef/nodes" ] + }, + Chef::Node::PuppetExternalNode => { + :command => "" + }, + :rest => { + :search_url => "http://localhost:3000/nodes/#{node_name}" + }, + :iclassify => { + :search_url => "http://localhost:3000/nodes/#{node_name}" + } +]) + + diff --git a/chef/examples/config/chef-solo.rb b/chef/examples/config/chef-solo.rb new file mode 100644 index 0000000000..2a85253b37 --- /dev/null +++ b/chef/examples/config/chef-solo.rb @@ -0,0 +1,11 @@ +# +# Example Chef Solo Config + +cookbook_path File.join(File.dirname(__FILE__), "cookbooks") +node_path File.join(File.dirname(__FILE__), "nodes") +search_index_path File.join(File.dirname(__FILE__), "..", "search_index") +log_level :info +file_store_path "/tmp/chef" +file_cache_path "/tmp/chef/cache" + +Chef::Log::Formatter.show_time = false diff --git a/chef/examples/config/cookbooks/fakefile/attributes/first.rb b/chef/examples/config/cookbooks/fakefile/attributes/first.rb new file mode 100644 index 0000000000..927dafe967 --- /dev/null +++ b/chef/examples/config/cookbooks/fakefile/attributes/first.rb @@ -0,0 +1,2 @@ +Chef::Log.debug("You are the first of fakefile's attributes") +friends("you said we wuz visiting em") \ No newline at end of file diff --git a/chef/examples/config/cookbooks/fakefile/definitions/test.rb b/chef/examples/config/cookbooks/fakefile/definitions/test.rb new file mode 100644 index 0000000000..ce32293943 --- /dev/null +++ b/chef/examples/config/cookbooks/fakefile/definitions/test.rb @@ -0,0 +1,13 @@ +define :monkey, :eats => "bananna" do + file "/tmp/monkeynews-#{params[:name]}" do + owner "root" + mode 0644 + action :create + end + + file "/tmp/monkeynews-#{params[:name]}-second-#{params[:eats]}" do + owner "root" + mode 0644 + notifies :touch, resources(:file => "/tmp/monkeynews-#{params[:name]}"), :immediately + end +end \ No newline at end of file diff --git a/chef/examples/config/cookbooks/fakefile/files/default/remote_test/another/turn/the_page.txt b/chef/examples/config/cookbooks/fakefile/files/default/remote_test/another/turn/the_page.txt new file mode 100644 index 0000000000..9664cb3e15 --- /dev/null +++ b/chef/examples/config/cookbooks/fakefile/files/default/remote_test/another/turn/the_page.txt @@ -0,0 +1 @@ +Classic rock is awesome. diff --git a/chef/examples/config/cookbooks/fakefile/files/default/remote_test/another/window.txt b/chef/examples/config/cookbooks/fakefile/files/default/remote_test/another/window.txt new file mode 100644 index 0000000000..68a3bf17e4 --- /dev/null +++ b/chef/examples/config/cookbooks/fakefile/files/default/remote_test/another/window.txt @@ -0,0 +1 @@ +appleseed? \ No newline at end of file diff --git a/chef/examples/config/cookbooks/fakefile/files/default/remote_test/mycat.txt b/chef/examples/config/cookbooks/fakefile/files/default/remote_test/mycat.txt new file mode 100644 index 0000000000..d4d8511934 --- /dev/null +++ b/chef/examples/config/cookbooks/fakefile/files/default/remote_test/mycat.txt @@ -0,0 +1 @@ +is a very nice kitty \ No newline at end of file diff --git a/chef/examples/config/cookbooks/fakefile/files/default/the_park.txt b/chef/examples/config/cookbooks/fakefile/files/default/the_park.txt new file mode 100644 index 0000000000..c71308a6ca --- /dev/null +++ b/chef/examples/config/cookbooks/fakefile/files/default/the_park.txt @@ -0,0 +1,3 @@ +Is very pretty on a Saturday at 7:50 in August. Hottest day of the year so far in Seattle. + +something \ No newline at end of file diff --git a/chef/examples/config/cookbooks/fakefile/recipes/default.rb b/chef/examples/config/cookbooks/fakefile/recipes/default.rb new file mode 100644 index 0000000000..12ba3e69d9 --- /dev/null +++ b/chef/examples/config/cookbooks/fakefile/recipes/default.rb @@ -0,0 +1,151 @@ +execute "write-foolio" do + command <<-EOH + echo 'monkeypants #{node[:ipaddress]} #{node[:friends]}' > /tmp/foolio + EOH + user "daemon" +end + +script "monkeylikesit" do + code %q{ +print "Woot!\n"; +open(FILE, ">", "/tmp/monkeylikesit") or die "Cannot open monkeylikesit"; +print FILE "You have some interesting hobbies #{node[:ipaddress]}"; +close(FILE); +} + interpreter "perl" +end + +perl "foobar" do + code %q{ +print "Woot!\n"; + } +end + +unless @node[:operatingsystem] == "Darwin" + package "emacs" + + package "emacs" do + action :remove + end + + package "emacs" do + version "22.1-0ubuntu10" + action :install + end + + package "emacs" do + action :upgrade + end + + package "emacs" do + action :purge + end +end + +package "ruby-djbdns" do + action [ :install, :remove, :upgrade, :purge ] + provider Chef::Provider::Package::Rubygems +end + +gem_package "ruby-djbdns" do + action [ :install, :remove, :upgrade, :purge ] + provider Chef::Provider::Package::Rubygems +end + +file "/tmp/foo" do + owner "adam" + mode 0644 + action :create + notifies :delete, resources(:file => "/tmp/glen"), :delayed +end + +remote_file "/tmp/the_park.txt" do + owner "adam" + mode 0644 + source "the_park.txt" + action :create +end + +remote_directory "/tmp/remote_test" do + owner "adam" + mode 0755 + source "remote_test" + files_owner "root" + files_group(node[:operatingsystem] == "Debian" ? "root" : "wheel") + files_mode 0644 + files_backup false +end + +template "/tmp/foo-template" do + owner "adam" + mode 0644 + source "monkey.erb" + variables({ + :one => 'two', + :el_che => 'rhymefest', + :white => { + :stripes => "are the best", + :at => "the sleazy rock thing", + } + }) +end + +link "/tmp/foo" do + link_type :symbolic + target_file "/tmp/xmen" +end + +# 0.upto(1000) do |n| +# file "/tmp/somefile#{n}" do +# owner "adam" +# mode 0644 +# action :create +# end +# end + +directory "/tmp/home" do + owner "root" + mode 0755 + action :create +end + +search(:user, "*") do |u| + directory "/tmp/home/#{u['name']}" do + if u['name'] == "nobody" && @node[:operatingsystem] == "Darwin" + owner "root" + else + owner "#{u['name']}" + end + mode 0755 + action :create + end +end + +monkey "snoopy" do + eats "vegetables" +end + +monkey "snack" + +# user "katie" do +# uid 9999 +# gid 100 +# home "/tmp/home/katie" +# shell "/bin/bash" +# comment "Katie Bethell" +# action :create +# end +# +# user "katie" do +# gid 101 +# action :modify +# end +# +# user "katie" do +# shell "/home/katie" +# action :manage +# end +# +# user "katie" do +# action [ :lock, :unlock, :remove ] +# end diff --git a/chef/examples/config/cookbooks/fakefile/templates/default/monkey.erb b/chef/examples/config/cookbooks/fakefile/templates/default/monkey.erb new file mode 100644 index 0000000000..29c2639381 --- /dev/null +++ b/chef/examples/config/cookbooks/fakefile/templates/default/monkey.erb @@ -0,0 +1,5 @@ +This is a <%= @one %> with <%= @el_che %> + +It was rendered on a system with the ipaddress of <%= @node[:ipaddress] %> + +But it's all about the conquest, with <%= @node[:fqdn ] %> diff --git a/chef/examples/config/cookbooks/rubygems_server/attributes/first.rb b/chef/examples/config/cookbooks/rubygems_server/attributes/first.rb new file mode 100644 index 0000000000..d1b7bd6a23 --- /dev/null +++ b/chef/examples/config/cookbooks/rubygems_server/attributes/first.rb @@ -0,0 +1 @@ +rubygems("are awesome") diff --git a/chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-scp-1.0.1.gem b/chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-scp-1.0.1.gem new file mode 100644 index 0000000000..d3eafbca10 Binary files /dev/null and b/chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-scp-1.0.1.gem differ diff --git a/chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-sftp-2.0.1.gem b/chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-sftp-2.0.1.gem new file mode 100644 index 0000000000..e9bc3c2276 Binary files /dev/null and b/chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-sftp-2.0.1.gem differ diff --git a/chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-ssh-2.0.3.gem b/chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-ssh-2.0.3.gem new file mode 100644 index 0000000000..b11cbe00cc Binary files /dev/null and b/chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-ssh-2.0.3.gem differ diff --git a/chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-ssh-gateway-1.0.0.gem b/chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-ssh-gateway-1.0.0.gem new file mode 100644 index 0000000000..545f850a71 Binary files /dev/null and b/chef/examples/config/cookbooks/rubygems_server/files/default/packages/net-ssh-gateway-1.0.0.gem differ diff --git a/chef/examples/config/cookbooks/rubygems_server/recipes/default.rb b/chef/examples/config/cookbooks/rubygems_server/recipes/default.rb new file mode 100644 index 0000000000..6b60456094 --- /dev/null +++ b/chef/examples/config/cookbooks/rubygems_server/recipes/default.rb @@ -0,0 +1,8 @@ +remote_directory "/srv/gems" do + owner "www-data" + mode 0755 + source "packages" + files_owner "www-data" + files_group "www-data" + files_mode 0644 +end diff --git a/chef/examples/config/cookbooks/servicetest/recipes/default.rb b/chef/examples/config/cookbooks/servicetest/recipes/default.rb new file mode 100644 index 0000000000..812b48e19d --- /dev/null +++ b/chef/examples/config/cookbooks/servicetest/recipes/default.rb @@ -0,0 +1,12 @@ +service "puppet-client" do + service_name "puppet" + pattern "puppetd" + action :enable +end + +file "/tmp/foo" do + owner "aj" + mode 0644 + action :create + notifies :start, resources(:service => "puppet-client"), :immediate +end diff --git a/chef/examples/config/cookbooks/tempfile/attributes/second.rb b/chef/examples/config/cookbooks/tempfile/attributes/second.rb new file mode 100644 index 0000000000..df791b8429 --- /dev/null +++ b/chef/examples/config/cookbooks/tempfile/attributes/second.rb @@ -0,0 +1 @@ +monkey "poots" \ No newline at end of file diff --git a/chef/examples/config/cookbooks/tempfile/recipes/default.rb b/chef/examples/config/cookbooks/tempfile/recipes/default.rb new file mode 100644 index 0000000000..b4fa86ac32 --- /dev/null +++ b/chef/examples/config/cookbooks/tempfile/recipes/default.rb @@ -0,0 +1,24 @@ +file "/tmp/glen" do + owner "adam" + mode 0755 + action "create" +end + +file "/tmp/metallica" do + action [ :create, :touch, :delete ] +end + +directory "/tmp/marginal" do + owner "adam" + mode 0755 + action :create +end + +remote_directory "/tmp/rubygems" do + owner "adam" + mode 0755 + source "packages" + files_owner "adam" + files_group "adam" + files_mode 0755 +end diff --git a/chef/examples/config/nodes/adam.rb b/chef/examples/config/nodes/adam.rb new file mode 100644 index 0000000000..c3e8e4bc16 --- /dev/null +++ b/chef/examples/config/nodes/adam.rb @@ -0,0 +1,14 @@ +## +# Nodes should have a unique name +## +name "adam" + +## +# Nodes can set arbitrary arguments +## +owner "Adam Jacob" + +## +# Nodes should have recipes +## +recipes "tempfile", "fakefile" diff --git a/chef/examples/config/nodes/default.rb b/chef/examples/config/nodes/default.rb new file mode 100644 index 0000000000..d365690c60 --- /dev/null +++ b/chef/examples/config/nodes/default.rb @@ -0,0 +1,9 @@ +## +# Nodes can set arbitrary arguments +## +owner "Adam Jacob" + +## +# Nodes should have recipes +## +recipes "tempfile", "fakefile" diff --git a/chef/examples/config/nodes/junglist.gen.nz.rb b/chef/examples/config/nodes/junglist.gen.nz.rb new file mode 100644 index 0000000000..70ce7661b5 --- /dev/null +++ b/chef/examples/config/nodes/junglist.gen.nz.rb @@ -0,0 +1,14 @@ +## +# Nodes should have a unique name +## +name "junglist.gen.nz" + +## +# Nodes can set arbitrary arguments +## +owner "AJ Christensen" + +## +# Nodes should have recipes +## +recipes "servicetest" diff --git a/chef/examples/config/nodes/latte.rb b/chef/examples/config/nodes/latte.rb new file mode 100644 index 0000000000..8987738151 --- /dev/null +++ b/chef/examples/config/nodes/latte.rb @@ -0,0 +1,14 @@ +## +# Nodes should have a unique name +## +name "latte.local" + +## +# Nodes can set arbitrary arguments +## +owner "Adam Jacob" + +## +# Nodes should have recipes +## +recipes "tempfile", "fakefile" diff --git a/chef/examples/mrepo/Rakefile b/chef/examples/mrepo/Rakefile new file mode 100644 index 0000000000..e69de29bb2 diff --git a/chef/examples/node.rb b/chef/examples/node.rb new file mode 100644 index 0000000000..ef1e6a73fa --- /dev/null +++ b/chef/examples/node.rb @@ -0,0 +1,17 @@ +## +# Nodes should have a unique name +## +name "ops1prod" + +## +# Nodes can set arbitrary arguments +## +sunshine "in" +something "else" +that "is a cool ass trick" + +## +# Nodes should have recipes +## +recipes "operations-master", "operations-monitoring" + diff --git a/chef/examples/node.yml b/chef/examples/node.yml new file mode 100644 index 0000000000..d61a14875d --- /dev/null +++ b/chef/examples/node.yml @@ -0,0 +1,134 @@ +--- +parameters: + innodb_buffer_pool_size: 150M + kernel: Linux + serialnumber: 0123456789 + processorcount: "2" + operatingsystemrelease: 2.6.18-53.1.4.el5 + tinydns_ipaddress: 208.113.71.77 + rubysitedir: /usr/lib/ruby/site_ruby/1.8 + lsbrelease: ":core-3.1-amd64:core-3.1-ia32:core-3.1-noarch:graphics-3.1-amd64:graphics-3.1-ia32:graphics-3.1-noarch" + hardwaremodel: x86_64 + uniqueid: 007f0100 + ipaddress: 208.113.71.76 + swapfree: 2.00 GB + puppet_class: + - operations-master + - base + - iptables + - runit + - puppet-client + - sudo + - zsh + - subversion-client + - ruby + - man + - openssh + - build-essential + - rsync-client + - munin-node + - resolver + - iclassify-agent + - openldap-auth + - openldap-client + - nscd + - perl + - nagios-nrpe + - ntp-client + - ntp + - postfix + - emacs + - centos + - puppet-server + - mysql-server + - djbdns-server + - djbdns-base + - djbdns-public-cache + - openldap-server + - iclassify-server + - apache2 + - apache2-module-status + - apache2-module-alias + - apache2-module-auth_basic + - apache2-module-authn_file + - apache2-module-authz_default + - apache2-module-authz_groupfile + - apache2-module-authz_host + - apache2-module-authz_user + - apache2-module-autoindex + - apache2-module-dir + - apache2-module-env + - apache2-module-mime + - apache2-module-negotiation + - apache2-module-setenvif + - apache2-module-log_config + - perlbal + - mongrel-runit + - rails-twoohtwo + - mysql-client + - java + - wildcard-cert + - apache2-module-ldap + - gems-server + - operations-monitoring + - munin-moonin + - apache2-module-fcgid + - apache2-module-ssl + - apache2-module-authnz_ldap + - nagios-server + - subversion-server + - apache2-module-dav + - apache2-module-dav_svn + - trac + - apache2-module-proxy + - apache2-module-proxy_http + - apache2-module-rewrite + - apache2-module-deflate + - apache2-module-headers + puppet_env: + - prod + - prod + memorysize: "1.96" + fqdn: ops1prod.sfo.zoosk.com + kernelrelease: 2.6.18-53.1.4.el5 + ps: ps -ef + type: Node + mongrel_servers: "16" + hardwareisa: x86_64 + apache_listen_ports: + - "80" + - "443" + domain: sfo.zoosk.com + lsbdistdescription: CentOS release 5 (Final) + id: Node:1 + tinydns_internal_ipaddress: 127.0.01 + axfr_ipaddress: 208.113.71.77 + macaddress_eth0: 00:30:48:96:3D:72 + lsbdistrelease: "5" + memoryfree: 638.67 MB + manufacturer: Supermicro + sshrsakey: AAAAB3NzaC1yc2EAAAABIwAAAQEAzZBzuD14E6KJT3YKULXM9jEOIiC/efkn8+rK4yePLwDSNypfClZt8+ThUGlGQVZF0Z1kMa1hLfZD+Puhe9Vp4hMkTBmlvATiWEZduUvkZ7Fh56mnstjmwYoxkvP8FG/ItQtfNJY3UgmtdeeoVYw566P5E9HKKWFUQp5IpZBUpsttVuY/b7ro/ray1lY/bWJ7ykYVwcGWVjsM+W6N0je+mouLcDN3QJAMzMwVuf3MzagKcawvM6qPDJ2Lv6lxRiVn1HZwv+YoPS7+S0/wDl4tZo9+mDb1jdI++af27Q8hKUTjjyjlWUcHG9eDWYjMZPYbY5Qv6FWG6/fEwZ0zu+sVhQ== + lsbdistcodename: Final + slapd_type: master + macaddress_eth1: 00:30:48:96:3D:73 + productname: PDSMi + mysql_server_id: "1" + rubyversion: 1.8.5 + hostname: ops1prod + puppetversion: 0.24.1 + public_dns_cache_ipaddress: 192.168.1.110 + processor0: Intel(R) Xeon(R) CPU 3050 @ 2.13GHz + architecture: x86_64 + facterversion: 1.3.8 + swapsize: 2.00 GB + operatingsystem: CentOS + macaddress: 00:30:48:96:3D:72 + processor1: Intel(R) Xeon(R) CPU 3050 @ 2.13GHz + ec2: "false" + ipaddress_eth0: 208.113.71.76 + mongrel_port_number: "5000" + lsbdistid: CentOS + sshdsakey: AAAAB3NzaC1kc3MAAACBANC70lacMCW6+5QtqOAD7Z/GQ7ChywuX332sbZ9tk6PE6HpCy9PoEjs4MZSrYnqeXxXq2XTRwO4e9agf+6z2gzzOZP3QZj2qoVl7WgTVvvgn1c/KbKcO7/wZXKOv2qg6/vzgrgd0wYUp+1Of04uVdbxRshR2QMY7x67bKw3vvDCbAAAAFQCsW+LA/AA2JxmOCRlZC/DAZn/l4wAAAIEAi9Z1DnYg88KV4BQWGCSAdDkJ0O5maUC12GZPQUDKY+AQU+ilS9QBo3Su0Zo9rrlygNrqyVryIbH7fktz81zj410kskktT6JvUsIR5Ep6C/GTZD8+372AsVQQ+LE+Ot3PXPBntVq2uRRum9wRKul2EZ8+uOhh3gZV2l4WdEg/07sAAACANm3CUM/+grYwDg0Uv6dNgcwsQsXHxfSUbPHGVdiEuf7WjQhNgVQffEwGHOS1xvfv2nvbGFnTnTDuIOo45vhBUmbv9s7NuRhn++M8ZwL+pLAq7BbFCeP4y0WvKOTJdupiLrgVH3KGRFP0djpOagueNQr9zcscTJR3eagImkb8aPs= + ipaddress_eth1: 192.168.1.110 +classes: +- operations-master diff --git a/chef/examples/sample_definition.rb b/chef/examples/sample_definition.rb new file mode 100644 index 0000000000..f536369290 --- /dev/null +++ b/chef/examples/sample_definition.rb @@ -0,0 +1,82 @@ +web_server "monchichi" do + one "something" + two "something else" +end + +runit_service "bobo" do + directory "monkey" + downif "/bin/false is true" + templatedir "something" +end + +define :runit_service, :directory => "/etc/sv", :downif => "/bin/false", :templatedir => nil do + require_recipe "runit" + + validate( + params, + { + :directory => { :required => true }, + :downif => { :required => true }, + :templatedir => { :required => false }, + } + ) + + file "#{param[:directory]}-#{param[:name]}" do + path "#{param[:directory]}/#{param[:name]}" + insure "directory" + owner "root" + group "root" + mode 0755 + end + + file "#{param[:directory]}/#{param[:name]}/log" do + insure "directory" + owner "root" + group "root" + mode 0755 + end + + file "#{param[:directory]}/#{param[:name]}/log/main" do + insure "directory" + owner "root" + group "root" + mode 0755 + end + + symlink "/etc/init.d/#{param[:name]}" do + sv_dir = case node[:lsbdistid] + when 'CentOS': "/usr/local/bin/sv" + else: "/usr/bin/sv" + end + source_file = sv_dir + end + + symlink "/var/service/#{param[:name]}" do + source_file "#{param[:directory]}/#{param[:name]}" + end + + service "#{param[:name]}" do + supports :status => true, :restart => true + end + + template_file "#{param[:directory]}/#{param[:name]}/log/run" do + content "#{param[:templatedir]}/log-run.erb" + owner "root" + group "root" + mode 755 + notifies resource("service[#{param[:name]}]") + end + + template_file "#{param[:directory]}/#{param[:name]}/run" do + content "#{param[:templatedir]}/run.erb" + owner root + group root + mode 755 + notifies resource("service[#{param[:name]}]") + end + + exec "#{param[:name]}-down" do + command "/etc/init.d/#{param[:name]} down" + only_if "#{downif}" + end +end diff --git a/chef/examples/sample_recipe.rb b/chef/examples/sample_recipe.rb new file mode 100644 index 0000000000..6abb31bfcd --- /dev/null +++ b/chef/examples/sample_recipe.rb @@ -0,0 +1,77 @@ +require_recipe "openldap" +require_recipe "openldap::client" +require_recipe "openldap::server" +require_recipe "resolver" +require_recipe "base" + +exec "restart-apache" do + path "/usr/bin:/usr/local/bin" + command "/etc/init.d/apache2 restart" + action :nothing +end + +service "apache2" do + insure "running" + has_restart true +end + +file "/etc/nsswitch.conf" do + owner "root" + group "root" + mode 0644 + notifies :restart, resources("service[openldap]"), :immediately +end + +service "apache2" do + action "enabled" + subscribes :restart, resources("/etc/nsswitch.conf"), :immediately +end + +file "/etc/ldap.conf" do + owner "root" + group "root" + mode 0644 +end + +file "/srv/monkey" do + insure "present" + owner "root" + group "root" + mode 0644 +end + +file "/srv/owl" do + insure "present" + owner "root" + group "root" + mode 0644 +end + +file "/srv/zen" do + insure "absent" +end + +# +# file "/srv/monkey" do |f| +# f.insure = "present" +# f.owner = "adam" +# f.group = "adam" +# f.mode = 0644 +# f.before = resources(:file => "/etc/nsswitch.conf") +# end +# +# file "/etc/ldap-nss.conf" do |f| +# f.insure = "present" +# f.owner = "root" +# f.group = "root" +# f.mode = 0644 +# f.notifies = :refresh, resources(:file => "/etc/ldap.conf") +# end +# +# file "/etc/coffee.conf" do |f| +# f.insure = "present" +# f.owner = "root" +# f.group = "root" +# f.mode = 0644 +# f.subscribes = :polio, resources(:file => "/etc/nsswitch.conf") +# end \ No newline at end of file diff --git a/chef/examples/search_index/segments b/chef/examples/search_index/segments new file mode 100644 index 0000000000..01d633b27e Binary files /dev/null and b/chef/examples/search_index/segments differ diff --git a/chef/examples/search_index/segments_0 b/chef/examples/search_index/segments_0 new file mode 100644 index 0000000000..b642403384 Binary files /dev/null and b/chef/examples/search_index/segments_0 differ diff --git a/chef/examples/search_syntax.rb b/chef/examples/search_syntax.rb new file mode 100644 index 0000000000..4be57b7802 --- /dev/null +++ b/chef/examples/search_syntax.rb @@ -0,0 +1,10 @@ +search(:users, "allowed:#{node[:hostname]} or allowed:#{node[:tags]}") do |u| + user "#{u['username']}" do + uid "#{u['uid']}" + gid "#{u['gid']}" + username "#{u['username']}" + homedir "#{u['homedir']}" + action :create + end +end + diff --git a/chef/examples/user_index.pl b/chef/examples/user_index.pl new file mode 100755 index 0000000000..e78a8125f4 --- /dev/null +++ b/chef/examples/user_index.pl @@ -0,0 +1,115 @@ +#!/usr/bin/perl +# +# M00se on the L00se + +package Chef::Rest; + +use strict; +use warnings; + +use LWP::UserAgent; +use URI; +use Params::Validate qw(:all); +use JSON::Syck; + +sub new { + my $self = shift; + my %p = validate(@_, + { + content_type => { type => SCALAR }, + }, + ); + my $ref = { + 'ua' => LWP::UserAgent->new, + 'content_type' => $p{'content_type'}, + }; + bless $ref, $self; +} + +sub load { + my $self = shift; + my $data = shift; + return JSON::Syck::Load($data); +} + +sub get { + my $self = shift; + my %p = validate(@_, + { + url => { type => SCALAR }, + params => { type => ARRAYREF, optional => 1 }, + }, + ); + + my $url = URI->new($p{'url'}); + if (defined($p{'params'})) { + $url->query_form($p{'params'}); + } + my $req = HTTP::Request->new('GET' => $url); + $req->content_type($self->{'content_type'}); + return $self->ua->request($req); +} + +sub delete { + my $self = shift; + my %p = validate(@_, + { + url => { type => SCALAR }, + }, + ); + my $req = HTTP::Request->new('DELETE' => $p{'url'}); + $req->content_type($self->{'content_type'}); + return $self->ua->request($req); +} + +sub put { + my $self = shift; + my %p = validate(@_, + { + url => { type => SCALAR }, + data => 1, + }, + ); + my $data = JSON::Syck::Dump($p{'data'}); + my $req = HTTP::Request->new('PUT' => $p{'url'}); + $req->content_type($self->{'content_type'}); + $req->content_length(do { use bytes; length($data) }); + $req->content($data); + return $self->ua->request($req); +} + +sub post { + my $self = shift; + my %p = validate(@_, + { + url => { type => SCALAR }, + data => { required => 1 }, + }, + ); + my $data = JSON::Syck::Dump($p{'data'}); + my $req = HTTP::Request->new('POST' => $p{'url'}); + $req->content_type($self->{'content_type'}); + $req->content_length(do { use bytes; length($data) }); + $req->content($data); + return $self->{ua}->request($req); +} + +my $rest = Chef::Rest->new(content_type => 'application/json'); + +while (my @passwd = getpwent) { + print "Ensuring we have $passwd[0]\n"; + $rest->post( + url => 'http://localhost:4000/search/user/entries', + data => { + id => $passwd[0], + name => $passwd[0], + uid => $passwd[2], + gid => $passwd[3], + gecos => $passwd[6], + dir => $passwd[7], + shell => $passwd[8], + change => '', + expire => $passwd[9], + } + ) +} diff --git a/chef/examples/user_index.rb b/chef/examples/user_index.rb new file mode 100755 index 0000000000..485cff81b8 --- /dev/null +++ b/chef/examples/user_index.rb @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# +# Create a users index, based on /etc/passwd + +require 'etc' +require File.join(File.dirname(__FILE__), "..", "lib", "chef") + +Chef::Config[:log_level] = :info +r = Chef::REST.new("http://localhost:4000") + +users = Array.new +Etc.passwd do |passwd| + Chef::Log.info("Ensuring we have #{passwd.name}") + r.post_rest("search/user/entries", + { + :id => passwd.name, + :name => passwd.name, + :uid => passwd.uid, + :gid => passwd.gid, + :gecos => passwd.gecos, + :dir => passwd.dir, + :shell => passwd.shell, + :change => passwd.change, + :expire => passwd.expire + } + ) +end -- cgit v1.2.1