chef.snippets 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. # Opscode Chef Cookbook Recipe Resources
  2. # Snippet by: Mike Smullin <mike@smullindesign.com>
  3. # Based on: http://wiki.opscode.com/display/chef/Resources
  4. # @TODO: Include Meta attributes and actions in all snippets
  5. # @TODO: Finish writing snippets for remaining Resources
  6. snippet cookbook_file
  7. # Cookbook File resource
  8. cookbook_file ${1:"/path/to/file"} do # The remote path where the file will reside
  9. ${2:#}backup ${3} # How many backups of this file to keep. Set to false if you want no backups
  10. ${4:#}group ${5} # The group owner of the file (string or id)
  11. ${6:#}mode ${7} # The octal mode of the file - e.g. 0755
  12. ${8:#}owner ${9} # The owner for the file
  13. ${10:#}source ${11} # The basename of the source file
  14. ${12:#}cookbook ${13} # The cookbook this file is stored in
  15. ${14:#}${15: action :create} # Create this file (Default)
  16. ${16:#}${17: action :create_if_missing} # Create only if it doesn't exist yet
  17. ${18:#}${19: action :delete} # Delete this file
  18. end
  19. snippet execute
  20. # Execute resource
  21. execute ${1:"command to execute"} do # The command to execute
  22. ${2:#}creates ${3:nil} # A file this command creates - if the file exists, the command will not be run.
  23. ${4:#}cwd ${5:nil} # Current working directory to run the command from.
  24. ${6:#}environment ${7:nil} # A hash of environment variables to set before running this command.
  25. ${8:#}group ${9:nil} # A group name or group ID that we should change to before running this command.
  26. ${10:#}path ${11:nil} # An array of paths to use when searching for the command. Nil uses system path.
  27. ${12:#}returns ${13:0} # The return value of the command - this resource raises an exception if the return value does not match.
  28. ${14:#}timeout ${15:nil} # How many seconds to let the command run before timing it out.
  29. ${16:#}user ${17:nil} # A user name or user ID that we should change to before running this command.
  30. ${18:#}umask ${19:nil} # Umask for files created by the command
  31. ${20:#}${21:action :run} # Run this command (Default)
  32. ${22:#}${23:action :nothing} # Do not run this command
  33. end
  34. snippet link
  35. # Link resource
  36. link ${1:"/target/file"} do # The file name of the link
  37. ${2:#}to ${3} # The real file you want to link to
  38. ${4:#}link_type ${5:symbolic} # Either :symbolic or :hard
  39. ${6:#}owner ${7} # The owner of the symlink
  40. ${8:#}group ${9} # The group of the symlink
  41. ${10:#}${11:action :create} # Create a link (Default)
  42. ${12:#}${13:action :delete} # Delete a link
  43. end
  44. snippet package
  45. # Package resource
  46. package ${1:"package_name"} do # Name of the package to install
  47. ${2:#}version ${3:nil} # The version of the package to install/upgrade
  48. ${4:#}response_file ${5:nil} # An optional response file - used to pre-seed packages (note: the file is fetched by Remote File)
  49. ${6:#}source ${7} # Used to provide an optional package source for providers that use a local file (rubygems, dpkg and rpm)
  50. ${8:#}options ${9:nil} # Add additional options to the underlying package command
  51. ${10:#}gem_binary ${11:gem} # A gem_package attribut to specify a gem binary. Useful for installing ruby 1.9 gems while running chef in ruby 1.8
  52. ${12:#}${13:action :install} # Install a package - if version is provided, install that specific version (Default)
  53. ${14:#}${15:action :upgrade} # Upgrade a package - if version is provided, upgrade to that specific version
  54. ${16:#}${17:action :remove} # Remove a package
  55. ${18:#}${19:action :purge} # Purge a package (this usually entails removing configuration files as well as the package itself)
  56. end
  57. snippet service
  58. # Service resource
  59. service ${1:"service_name"} do # Name of the service
  60. ${2:#}enabled ${3:nil} # Whether the service is enabled at boot time
  61. ${4:#}running ${5:nil} # Make sure the service is running. Start if stopped
  62. ${6:#}pattern ${7} # Pattern to look for in the process table
  63. ${8:#}start_command ${9:nil} # Command used to start this service
  64. ${10:#}stop_command ${11:nil} # Command used to stop this service
  65. ${12:#}status_command ${13:nil} # Command used to check the service run status
  66. ${14:#}restart_command ${15:nil} # Command used to restart this service
  67. ${16:#}reload_command ${17:nil} # Command used to tell this service to reload its configuration
  68. ${18:#}supports ${19:false} # Features this service supports, ie :restart, :reload, :status
  69. ${20:#}${21:action :enable} # Enable this service
  70. ${22:#}${23:action :disable} # Disable this service
  71. ${24:#}${25:action :nothing} # Don't do anything with this service (Default)
  72. ${26:#}${27:action :start} # Start this service
  73. ${28:#}${29:action :stop} # Stop this service
  74. ${30:#}${31:action :restart} # Restart this service
  75. ${32:#}${33:action :reload} # Reload the configuration for this service
  76. end
  77. snippet file
  78. # File resource
  79. file ${1:"/path/to/file"} do # Path to the file
  80. ${2:#}backup ${3:5} # How many backups of this file to keep. Set to false if you want no backups.
  81. ${4:#}owner ${5} # The owner for the file
  82. ${6:#}group ${7} # The group owner of the file (string or id)
  83. ${8:#}mode ${9} # The octal mode of the file (4-digit format)
  84. ${10:#}content ${11:nil} # A string to write to the file. This will replace any previous content if set
  85. ${12:#}${13:action :create} # Create this file (Default)
  86. ${14:#}${15:action :delete} # Delete this file
  87. ${16:#}${17:action :touch} # Touch this file (update the mtime/atime)
  88. end
  89. snippet directory
  90. # Directory resource
  91. directory ${1:"/path/to/dir"} do # The path to the directory
  92. ${2:#}group ${3} # The group owner of the directory (string or id)
  93. ${4:#}mode ${5} # The octal mode of the directory, eg 0755
  94. ${6:#}owner ${7} # The owner for the directory
  95. ${10:#}recursive ${11:false} # When deleting the directory, delete it recursively. When creating the directory, create recursively (ie, mkdir -p)
  96. ${12:#}${13:action :create} # Create this directory (Default)
  97. ${14:#}${15:action :delete} # Delete this directory
  98. end
  99. snippet template
  100. # Template resource
  101. template ${1:"/path/to/file"} do # Path to the file
  102. ${2:#}cookbook ${3:nil} # Specify the cookbook where the template is located, default is current cookbook
  103. ${4:#}source ${5:nil} # Template source file. Found in templates/default for the cookbook
  104. ${6:#}variables ${7} # Variables to use in the template
  105. ${8:#}local ${9:false} # Is the template already present on the node?
  106. ${10:#}backup ${11:5} # How many backups of this file to keep. Set to false if you want no backups.
  107. ${12:#}owner ${13} # The owner for the file
  108. ${14:#}group ${15} # The group owner of the file (string or id)
  109. ${16:#}mode ${17} # The octal mode of the file (4-digit format)
  110. ${18:#}content ${19:nil} # A string to write to the file. This will replace any previous content if set
  111. ${20:#}${21:action :create} # Create the file (Default)
  112. ${22:#}${23:action :delete} # Delete this file
  113. ${24:#}${25:action :touch} # Touch this file (update the mtime/atime)
  114. end
  115. snippet svn
  116. # SCM Resource, Chef::Provider::Subversion
  117. svn ${1:"/destination/path"} do # Path to clone/checkout/export the source to
  118. ${2:#}repository ${3} # URI of the repository
  119. ${4:#}revision ${5:"HEAD"} # revision to checkout. can be symbolic, like "HEAD" or an SCM specific revision id
  120. ${6:#}reference ${7} # (Git only) alias for revision
  121. ${8:#}user ${9:nil} # System user to own the checked out code
  122. ${10:#}group ${11:nil} # System group to own the checked out code
  123. ${12:#}svn_username ${13} # (Subversion only) Username for Subversion operations
  124. ${14:#}svn_password ${15} # (Subversion only) Password for Subversion operations
  125. ${16:#}svn_arguments ${17} # (Subversion only) Extra arguments passed to the subversion command
  126. ${18:#}${19:action :sync} # Update the source to the specified revision, or get a new checkout (Default)
  127. ${20:#}${21:action :checkout} # Checkout the source. Does nothing if a checkout is available
  128. ${22:#}${23:action :export} # Export the source, excluding or removing any version control artifacts
  129. end
  130. snippet git
  131. # SCM Resource, Chef::Provider::Git
  132. git ${1:"/destination/path"} do # Path to clone/checkout/export the source to
  133. ${2:#}repository ${3} # URI of the repository
  134. ${4:#}revision ${5:"HEAD"} # revision to checkout. can be symbolic, like "HEAD" or an SCM specific revision id
  135. ${6:#}reference ${7} # (Git only) alias for revision
  136. ${8:#}user ${9:nil} # System user to own the checked out code
  137. ${10:#}group ${11:nil} # System group to own the checked out code
  138. ${12:#}depth ${13:nil} # (Git only) Number of past revisions to include in Git shallow clone
  139. ${14:#}enable_submodules ${15:"false"} # (Git only) performs a submodule init and submodule update
  140. ${16:#}remote ${17:"origin"} # (Git only) remote repository to use for syncing an existing clone
  141. ${18:#}ssh_wrapper ${19} # (Git only) path to a wrapper script for running SSH with git. GIT_SSH environment variable is set to this.
  142. ${20:#}${21:action :sync} # Update the source to the specified revision, or get a new clone (Default)
  143. ${22:#}${23:action :checkout} # Clone the source. Does nothing if a checkout is available
  144. ${24:#}${25:action :export} # Export the source, excluding or removing any version control artifacts
  145. end
  146. snippet deploy
  147. # Deploy resource
  148. deploy ${1:"/deploy/dir/"} do # Path to deploy to
  149. ${2:#}deploy_to ${3} # The "meta root" for your application.
  150. ${4:#}repository ${5} # URI of the repository
  151. ${6:#}repo ${7} # alias for repository
  152. ${8:#}revision ${9:"HEAD"} # revision to checkout. can be symbolic, like "HEAD" or an SCM specific revision id
  153. ${10:#}branch ${11} # alias for revision
  154. ${12:#}user ${13:nil} # System user to run the deploy as
  155. ${14:#}group ${15:nil} # System group to run the deploy as
  156. ${16:#}svn_username ${17} # (Subversion only) Username for Subversion operations}
  157. ${18:#}svn_password ${19} # (Subversion only) Password for Subversion operations}
  158. ${20:#}svn_arguments ${21} # (Subversion only) Extra arguments passed to the subversion command}
  159. ${22:#}shallow_clone ${23:nil} # (Git only) boolean, true sets clone depth to 5
  160. ${24:#}enable_submodules ${25:false} # (Git only) performs a submodule init and submodule update
  161. ${26:#}remote ${27:"origin"} # (Git only) remote repository to use for syncing an existing clone
  162. ${28:#}ssh_wrapper ${29} # (Git only) path to a wrapper script for running SSH with git. GIT_SSH environment variable is set to this.
  163. ${30:#}git_ssh_wrapper ${31} # alias for ssh_wrapper
  164. ${32:#}scm_provider ${33:Chef::Provider::Git} # SCM Provider to use.
  165. ${34:#}repository_cache ${35: "cached-copy"} # Name of the subdirectory where the pristine copy of your app's source is kept
  166. ${36:#}environment ${37} # A hash of the form {"ENV_VARIABLE"=>"VALUE"}}
  167. ${38:#}purge_before_symlink ${39:%w(log tmp/pids public/system)} # An array of paths, relative to app root, to be removed from a checkout before symlinking
  168. ${40:#}create_dirs_before_symlink ${41:%w(tmp public config)} # Directories to create before symlinking. Runs after purge_before_symlink
  169. ${42:#}symlinks ${43:"system" => "public/system", "pids" => "tmp/pids", "log" => "log"} # A hash that maps files in the shared directory to their paths in the current release
  170. ${44:#}symlink_before_migrate ${45:"config/database.yml" => "config/database.yml"} # A hash that maps files in the shared directory into the current release. Runs before migration
  171. ${46:#}migrate ${47:false} # Should the migration command be executed? (true or false)
  172. ${48:#}migration_command ${49} # A string containing a shell command to execute to run the migration
  173. ${50:#}restart_command ${51:nil} # A code block to evaluate or a string containing a shell command
  174. ${52:#}before_migrate ${53:"deploy/before_migrate.rb"} # A block or path to a file containing chef code to run before migrating
  175. ${54:#}before_symlink ${55:"deploy/before_symlink.rb"} # A block or path to a file containing chef code to run before symlinking
  176. ${56:#}before_restart ${57:"deploy/before_restart.rb"} # A block or path to a file containing chef code to run before restarting
  177. ${58:#}after_restart ${59:"deploy/after_restart.rb"} # A block or path to a file containing chef code to run after restarting
  178. ${60:#}${61::deploy} # Deploy the application (Default)
  179. ${62:#}${63::force_deploy} # For the revision deploy strategy, this removes any existing release of the same code version and re-deploys in its place
  180. ${64:#}${65::rollback} # Rollback the application to the previous release
  181. end