|
An overview of all available chef resources. Each description is broken in to several categories:
| Category |
Description |
| Actions |
The list of actions for this resource |
| Attributes |
The list of attributes for this resource |
| Providers |
The list of providers for this resource, along with any shortcut resource name. (You can use the shortcut resource name instead of specifying the provider attribute - apt_package rather than package with provider Chef::Provider::Package::Apt.) |
| Examples |
The first section, shows examples of using each action. |
Meta
These actions and attributes are available in every resource.
Actions
| Action |
Description |
Default |
| nothing |
Do nothing - useful if you want to specify a resource, but only notify it of other actions. |
Yes - in the absence of another default action, nothing is the default |
Attributes
Meta attributes do not have default values.
| Attribute |
Description |
| ignore_failure |
If true, we will continue running the recipe if this resource fails for any reason. (defaults to false) |
| notifies |
Notify another resource to take an action if this resource changes state for any reason. Syntax: notifies :action, resources(:service => "apache"), [:immediately | :delayed]. Defaults to notifying the resource at the end of the run (delayed). See examples. |
| not_if |
Do not apply this resource if the given string (shell command) or block (ruby code) results in return code 0 or is true. |
| only_if |
Only apply this resource if the given string (shell command) or block (ruby code) results in return code 0 or is true. |
| subscribes |
Take action on this resource if another resource changes state - the opposite of notifies. See examples. |
| provider |
The class name of a provider to use for this resource. |
| supports |
A hash of options that hint providers as to the capabilities of this resource. |
Further clarification on not_if and only_if. These attributes can be passed as strings or blocks.
- Strings are executed as a shell command. The attribute is true if the command returns 0.
- Blocks are Ruby code. The attribute is true if the result is true.
The behavior of the resource depends on whether the attribute was true.
- not_if - A true value indicates the action should not be performed.
- only_if - A true value indicates the resource's action should be performed..
 | New in Chef 0.8
For not_if and only_if, optional arguments are supported:
| Argument |
Description |
Example |
| :user |
Sets the user to run the command as |
not_if "grep adam /etc/passwd", :user => 'adam' |
| :group |
Sets the group to run the command as |
not_if "grep adam /etc/passwd", :group => 'adam' |
| :environment |
A Hash of environment variables to set |
not_if "grep adam /etc/passwd", :environment => { 'HOME' => "/home/adam" } |
| :cwd |
Sets the current working directory before running the command |
not_if "grep adam passwd", :cwd => '/etc' |
| :timeout |
Sets a timeout for the command |
not_if "sleep 10000", :timeout => 10 |
|
Further clarification for notifies and subscribes. The resources list can be either:
- resources(:resource => "name")
- resources("resource[name]")
Here, resources is a method in Chef. resource is a resource type as described on this page. name is the name of the resource. Examples below show both formats of specifying the arguments to the resources method, and either works.
|
|
Examples
Cron
Manage a cron entry. Attributes for schedule will default to '*' if not provided so only specify the schedule attributes that are applicable to your cron entry.
Create will update an entry if it shares the same name. The delete action will delete an entry with a matching name. Both notes only apply on a per-user basis.
Requires that a package providing crontab program is installed (typically cron).
Actions
| Action |
Description |
Default |
| create |
Create the crontab entry |
Yes |
| delete |
Delete the crontab entry |
|
Attributes
| Attribute |
Description |
Default Value |
| minute |
The minute this entry should run |
* |
| hour |
The hour this entry should run |
* |
| day |
The day this entry should run |
* |
| month |
The month this entry should run |
* |
| weekday |
The weekday this entry should run |
* |
| command |
The command to run |
|
| user |
The user to run command as |
root |
| mailto |
Set the MAILTO environment variable |
|
| path |
Set the PATH environment variable |
|
| home |
Set the HOME environment variable |
|
| shell |
Set the SHELL environment variable |
|
Providers
| Provider |
Shortcut Resource |
Default For Platforms |
| Chef::Provider::Cron |
|
All |
Examples
Deploy
The deploy resource is quite detailed and has a separate document.
Directory
Manage a directory.
Actions
| Action |
Description |
Default |
| create |
Create this directory |
Yes |
| delete |
Delete this directory |
|
Attributes
| Attribute |
Description |
Default Value |
| group |
The group owner of the directory (string or id) |
|
| mode |
The octal mode of the directory, eg 0755 |
|
| owner |
The owner for the directory |
|
| path |
Name attribute: The path to the directory |
name |
| recursive |
When deleting the directory, delete it recursively. When creating the directory, create recursively (ie, mkdir -p) |
false |
Providers
| Provider |
Shortcut Resource |
Default For Platforms |
| Chef::Provider::Directory |
|
All |
Examples
Erlang Call
Connects to a distributed erlang node and makes a call. See the documentation for erl_call in the OTP documentation for more information.
Like the Execute and Script resources, Erlang Call resources are not idempotent. Use the not_if and only_if meta parameters to guard the resource for idempotence.
Actions
| Action |
Description |
Default |
| run |
Run this erlang call |
Yes |
| nothing |
Do not run this command |
|
Attributes
| Attribute |
Description |
Default Value |
| code |
The erlang code to execute on the distributed node |
q(). |
| cookie |
The cookie of erlang node you connect to |
|
| distributed |
Starts a distributed erlang node if neccessary |
false |
| name_type |
Whether the node_name is an sname or name |
sname |
| node_name |
The node hostname to connect to |
chef@localhost |
Providers
| Provider |
Shortcut Resource |
Default For Platforms |
| Chef::Provider::ErlCall |
|
All |
Examples
Execute
Execute a command. Use Script resources to execute a script with a specific interpreter.
By their nature, Execute resources are not idempotent, as they are completely up to the user's imagination. Use the not_if or only_if meta parameters to guard the resource for idempotence.
Actions
| Action |
Description |
Default |
| run |
Run this command |
Yes |
| nothing |
Do not run this command |
|
Use action :nothing to set a command to only run if another resource notifies it.
Attributes
| Attribute |
Description |
Default Value |
| command |
Name attribute: The command to execute |
name |
| creates |
A file this command creates - if the file exists, the command will not be run. |
nil |
| cwd |
Current working directory to run the command from. |
nil |
| environment |
A hash of environment variables to set before running this command. |
nil |
| group |
A group name or group ID that we should change to before running this command. |
nil |
| path |
An array of paths to use when searching for the command. |
nil, uses system path |
| returns |
The return value of the command - this resource raises an exception if the return value does not match. |
0 |
| timeout |
How many seconds to let the command run before timing it out. |
nil |
| user |
A user name or user ID that we should change to before running this command. |
nil |
Providers
| Provider |
Shortcut Resource |
Default For Platforms |
| Chef::Provider::Execute |
|
All |
Examples
File
Manage files (see Template or Remote File if you want to manage contents).
Actions
| Action |
Description |
Default |
| create |
Create this file |
Yes |
| delete |
Delete this file |
|
| touch |
Touch this file (update the mtime/atime) |
|
Attributes
| Attribute |
Description |
Name Attribute |
| backup |
How many backups of this file to keep. Set to false if you want no backups. |
5 |
| group |
The group owner of the file (string or id) |
|
| mode |
The octal mode of the file - 0755 |
|
| owner |
The owner for the file |
|
| path |
Name attribute: The path to the file |
name |
A note about mode: When specifying the mode, the value can be a quoted string, eg "644". For a numeric value, it should be 5 digits, eg "00644" to ensure that Ruby can parse it correctly. For more detail, see Ticket CHEF-174.
Providers
| Provider |
Shortcut Resource |
Default For Platforms |
| Chef::Provider::File |
|
All |
Examples
Group
Manage a local group.
Actions
| Action |
Description |
Default |
| create |
Create the group. |
Yes |
| remove |
Remove the group. |
|
| modify |
Modify the group. |
|
| manage |
Manage the group. |
|
Attributes
| Attribute |
Description |
Default Value |
| group_name |
Name attribute: Name of the group. |
name |
| gid |
Group id. |
nil |
| members |
Include users in a group |
nil |
| append |
True=add these members to the group, false=these are the definitive group members |
false |
Providers
| Provider |
Shortcut Resource |
Default for Platforms |
| Chef::Provider::Group |
|
|
| Chef::Provider::Group::Groupadd |
|
All |
| Chef::Provider::Group::Dscl |
|
Mac OS X |
Examples
HTTP Request
Send an HTTP request with an arbitrary message. Handy for implementing your own callbacks!
Actions
| Action |
Description |
Default |
| get |
Send a GET request |
Yes |
| put |
Send a PUT request |
|
| post |
Send a POST request |
|
| delete |
Send a DELETE request |
|
Attributes
| Attribute |
Description |
Default Value |
| url |
The URL to send the request to |
nil |
| message |
Name attribute: The message to be sent to the URL (as the message parameter) |
name |
Providers
| Provider |
Shortcut Resource |
Default For Platforms |
| Chef::Provider::HttpRequest |
|
All |
Examples
Ifconfig
You can manage interfaces with the ifconfig resource. It is in early stage of development and hasn't been fully documented yet. In the Chef source, it is ifconfig.rb.
Link
Create symbolic or hard links.
Actions
| Action |
Description |
Default |
| create |
Create a link |
Yes |
| delete |
Delete a link |
|
Attributes
| Attribute |
Description |
Default Value |
| link_type |
Either :symbolic or :hard. |
:symbolic |
| to |
The real file you want to link to |
|
| target_file |
The file name of the link |
name |
Providers
| Provider |
Shortcut Resource |
Default For Platforms |
| Chef::Provider::Link |
|
All |
Examples
 | New in Chef 0.8
Log
Adds log entries from your recipes.
Actions
| Action |
Description |
Default |
| write |
Write to log |
Yes |
Attributes
| Attribute |
Description |
Default Value |
| level |
:info, :warn, :debug, or :error |
:info |
Providers
| Provider |
Shortcut Resource |
Default For Platforms |
| Chef::Provider::Log::ChefLog |
n/a |
All |
Examples
|
 | New in Chef 0.8
Mdadm
—
Manage mdadm software RAID devices.
Actions
Attributes
| Attribute |
Description |
Default Value |
| raid_device |
Name attribute:The RAID device name (/dev/md0) |
name |
| devices |
An array of devices to include in the RAID array |
|
| level |
The RAID level |
1 |
| chunk |
The chunk size |
16 |
Providers
| Provider |
Shortcut Resource |
Default For Platforms |
| Chef::Provider::Mdadm |
|
Linux |
Examples
|
Mount
Manage a mounted filesystem. Available in version 0.5.6. device_type available in 0.7.0.
Actions
| Action |
Description |
Default |
| mount |
Mount the device |
Yes |
| umount |
Unmount the device |
|
| remount |
Remount the device |
|
| enable |
Add entry to fstab |
|
| disable |
Remove entry from fstab |
|
Attributes
| Attribute |
Description |
Default Value |
| mount_point |
Name attribute:The directory/path where the device should be mounted |
name |
| device |
The special block device or remote node, a label or an uuid to mount. |
nil |
| device_type |
The type of the device specified. Can be :device, :label or :uuid |
:device |
| fstype |
The filesystem type of the device. |
nil |
| options |
Array or string containing mount options. |
defaults |
| dump |
Dump frequency in days, for fstab entry. |
0 |
| pass |
Pass number for fsck, for fstab entry. |
2 |
For now, device is required for umount and remount in order to check the mount command output for presence. This requirement will be removed at a later date.
For now, fstype is required. This requirement will be removed at a later date.
If options is a string, it will be converted to an array.
Providers
| Provider |
Shortcut Resource |
Default For Platforms |
| Chef::Provider::Mount |
|
All |
Examples
Package
Manage packages.
Actions
| Action |
Description |
Default |
| install |
Install a package - if version is provided, install that specific version |
Yes |
| upgrade |
Upgrade a package - if version is provided, upgrade to that specific version |
|
| remove |
Remove a package |
|
| purge |
Purge a package (this usually entails removing configuration files as well as the package itself) |
|
Attributes
| Attribute |
Description |
Default Value |
| package_name |
Name attribute: The name of the package to install |
name |
| version |
The version of the package to install/upgrade |
nil |
| response_file |
An optional response file - used to pre-seed packages (note: the file is fetched by Remote File) |
nil |
| source |
Used to provide an optional package source for providers that use a local file (rubygems, dpkg and rpm) |
|
| options |
Add additional options to the underlying package command |
nil |
| gem_binary |
A gem_package attribut to specify a gem binary. Useful for installing ruby 1.9 gems while running chef in ruby 1.8 |
gem |
For providers that install from a local file (rubygems, dpkg, rpm), grab the file either from a remote location via remote_file, or include it in the cookbook's files directory.
Providers
| Provider |
Shortcut Resource |
Default For Platforms |
Options |
| Chef::Provider::Package::Apt |
apt_package |
Debian, Ubuntu |
Yes |
| Chef::Provider::Package::Dpkg |
dpkg_package |
|
Yes |
| Chef::Provider::Package::EasyInstall |
easy_install_package |
|
|
| Chef::Provider::Package::Freebsd |
freebsd_package |
Freebsd |
No |
| Chef::Provider::Package::Macports |
macports_package |
Mac OS X |
No |
| Chef::Provider::Package::Portage |
portage_package |
Gentoo |
Yes |
| Chef::Provider::Package::Rpm |
rpm_package |
|
Yes |
| Chef::Provider::Package::Rubygems |
gem_package |
|
No |
| Chef::Provider::Package::Yum |
yum_package |
Redhat, Centos |
No |
| Chef::Provider::Package::Zypper |
zypper_package |
SuSE |
No |
The options attribute was added in 0.7.0.
Examples
Remote Directory
Recursively transfer a remote directory. Remote directory includes the attributes and actions of Directory. Name variable is still path.
Attributes
| Attribute |
Description |
Default Value |
| cookbook |
Specify the cookbook where the directory is located, default is current cookbook |
nil |
| files_backup |
Number of backup copies to keep for files in the directory |
5 |
| files_owner |
The owner for files in the directory. |
nil |
| files_group |
The group for files in the directory. |
nil |
| files_mode |
The octal mode for files in the directory - 0755. |
0644 |
| path |
Name attribute: Path to the directory. |
name |
| source |
From the cookbook's files/ directory. |
|
A note about mode: When specifying the mode, the value can be a quoted string, eg "644". For a numeric value, it should be 5 digits, eg "00644" to ensure that Ruby can parse it correctly. For more detail, see Ticket CHEF-174.
Providers
| Provider |
Shortcut Resource |
Default for Platforms |
| Chef::Provider::Directory::RemoteDirectory |
|
All |
Examples
Remote File
Transfer a file from a remote source. Remote File includes the attributes and actions of File. Name variable is still path.
Read more about Files to learn how Chef determines where to get the file.
Actions
| Action |
Description |
Default |
| create |
|
Yes |
Attributes
| Attribute |
Description |
Default Value |
| cookbook |
Specify the cookbook where the file is located, default is current cookbook |
nil |
| path |
Name attribute: Path to the file. |
name |
| source |
The source file in files/ directory, can be a URL |
nil |
| checksum |
For remote files with a URL, you can provide a checksum here so chef knows if it needs to redownload the file or not |
nil |
The source follows the same search path as Templates
Providers
| Provider |
Shortcut Resource |
Default for Platforms |
| Chef::Provider::File::RemoteFile |
|
All |
Examples
Route
Manage the system routing table.
Available in 0.5.2. Added in commits ceec2c 2491e4 192484.
Actions
| Action |
Description |
Default |
| add |
Add a route |
Yes |
| delete |
Delete a route |
|
Attributes
| Attribute |
Description |
Default Value |
| target |
Name attribute: The network or host address of the target route |
name |
| netmask |
The decimal representation of the network mask eg 255.255.255.0 |
|
| gateway |
The gateway for the route |
|
| metric |
The route metric as an integer |
|
| device |
Network interface to apply this route to |
|
| route_type |
The type of route as a symbol, either :host or :net |
:host |
Providers
| Provider |
Shortcut Resource |
Default For Platforms |
| Chef::Provider::Route |
|
All |
Examples
Ruby Block
Ticket CHEF-381 brought a new resource, "ruby_block" that can be used to execute a bit of Ruby code during a run. Ruby code in ruby_block resources is evaluated with other resources, whereas Ruby code outside ruby_block resources is evaluated before other resources.
Actions
| Action |
Description |
Default |
| create |
Create the Ruby Block |
Yes |
Attributes
| Attribute |
Description |
Default Value |
| block |
A block of Ruby code |
nil |
Providers
| Provider |
Shortcut Resource |
Default For Platforms |
| Chef::Provider::RubyBlock |
|
All |
Examples
SCM
Source code can be managed via the SCM resource. This is closely linked with doing application code deployment, so it is documented along with the Deploy Resource.
Script
Execute a script using the specified interpreter. Includes actions/attributes available to Execute resources: creates, cwd, environment, group, path, timeout, user. Predefined available script interpreters are bash, csh, perl, python and ruby.
The ruby script resource is different than the ruby_block resource described above, as it is created as a temporary file and executed like other script resources, rather than run inline.
By their nature, Script resources are not idempotent, as they are completely up to the user's imagination. Use the not_if or only_if meta parameters to guard the resource for idempotence.
Actions
| Action |
Description |
Default |
| run |
Run the script |
Yes |
Attributes
| Attribute |
Description |
Default Value |
| command |
Name attribute: Name of the command to execute. |
name |
| code |
Quoted script of code to execute. |
nil |
| interpreter |
Script interpreter to use for code execution. |
nil |
Providers
Providers for Chef::Resource::Script are aliases for different command interpreters.
| Provider |
Shortcut Resource |
| Chef::Resource::Script::Bash |
bash |
| Chef::Resource::Script::Csh |
csh |
| Chef::Resource::Script::Perl |
perl |
| Chef::Resource::Script::Python |
python |
| Chef::Resource::Script::Ruby |
ruby |
Examples
Service
Manage a service.
Actions
| Action |
Description |
Default |
| enable |
Enable this service |
|
| disable |
Disable this service |
|
| nothing |
Don't do anything with this service |
Yes |
| start |
Start this service |
|
| stop |
Stop this service |
|
| restart |
Restart this service |
|
| reload |
Reload the configuration for this service |
|
Attributes
| Attribute |
Description |
Default Value |
| service_name |
Name attribute: Name of the service. |
name |
| enabled |
Whether the service is enabled at boot time. |
nil |
| running |
Make sure the service is running. Start if stopped. |
nil |
| pattern |
Pattern to look for in the process table. |
service_name |
| start_command |
Command used to start this service. |
nil |
| stop_command |
Command used to stop this service. |
nil |
| status_command |
Command used to check the service run status. |
nil |
| restart_command |
Command used to restart this service. |
nil |
| reload_command |
Command used to tell this service to reload its configuration. |
nil |
| supports |
Features this service supports, ie :restart, :reload, :status. |
false |
Providers
By default, the init provider is used, which runs /etc/init.d/service_name with _command.
| Provider |
Shortcut Resource |
Default for Platform |
| Chef::Provider::Service::Init |
|
All |
| Chef::Provider::Service::Init::Debian |
|
Debian, Ubuntu |
| Chef::Provider::Service::Upstart |
|
|
| Chef::Provider::Service::Init::Freebsd |
|
Freebsd |
| Chef::Provider::Service::Init::Gentoo |
|
Gentoo |
| Chef::Provider::Service::Init::Redhat |
|
Redhat, Centos |
Examples
Template
Manage File contents with an embedded ruby (erb) template. Includes actions and attributes from File. path is the Name attribute. Read more about templates.
Templates follow the same File Specificity rules as remote_file and file resources.
Actions
| Action |
Description |
Default |
| create |
Create the file |
Yes |
Attributes
| Attribute |
Description |
Default Value |
| cookbook |
Specify the cookbook where the template is located, default is current cookbook |
nil |
| path |
Name attribute: The path to the file |
name |
| source |
Template source file. Found in templates/default for the cookbook. |
nil |
| variables |
Variables to use in the template. |
|
Source is found in the search path per the templates page
Providers
| Provider |
Shortcut Resource |
Default for Platforms |
| Chef::Provider::File::Template |
|
|
Examples
User
Manage a local user.
Actions
| Action |
Description |
Default |
| create |
Create the user. |
Yes |
| remove |
Remove the user. |
|
| modify |
Modify the user. |
|
| manage |
Manage the user. |
|
| lock |
Lock the user's password. |
|
| unlock |
Unlock the user's password. |
|
Attributes
| Attribute |
Description |
Default Value |
| username |
Name attribute: Name of the user. |
name |
| comment |
Gecos/Comment field. |
nil |
| uid |
Numeric user id. |
nil |
| gid |
Primary group id. |
nil |
| home |
Home directory location |
nil |
| shell |
Login shell. |
nil |
| password |
Shadow hash of password. |
nil |
| supports |
User features supported, eg :manage_home. |
:manage_home => false |
Providers
| Provider |
Shortcut Resource |
Default for Platforms |
| Chef::Provider::User |
|
|
| Chef::Provider::User::Useradd |
|
All |
| Chef::Provider::User::Dscl |
|
Mac OS X |
Prerequisites
In order to use the "password" attribute in Chef 0.5.6, you must have "ruby-shadow" installed. You can get this by installing the debian package "libshadow-ruby1.8".
Examples