π link
π link
Create symbolic links on the target system.
β‘ Actions
| Action | Description |
|---|---|
:create |
Create the symlink (default) |
:nothing |
Do nothing (use with notifications) |
π Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
link |
String | Resource name | Path of the symbolic link (auto-set from resource name) |
to |
String | required β οΈ | Target path the link points to |
force |
Boolean | false |
Force link creation β overwrite existing files/links |
π‘ When
forceistrue, both theforceandno_dereferenceflags are passed to the underlying command, allowing you to overwrite existing symlinks or files.
π How It Works
- Check existence β Checks if the link already exists
- Check target β If the link exists, reads its current target
- Create/Update β Only creates or updates the link if it doesnβt point to the correct target
- Idempotent β If the link already points to the correct target, no changes are made
π¬ Dry-Run Behavior
The current symlink target is read from the system. You see whether the link would be created or updated with the new target path.
π Examples
Create a symlink
link '/usr/local/bin/ruby' do
to '/usr/local/ruby-3.2/bin/ruby'
end
Force overwrite an existing link
link '/etc/nginx/sites-enabled/default' do
to '/etc/nginx/sites-available/myapp'
force true
end
Link a release directory (deploy pattern)
link '/opt/app/current' do
to '/opt/app/releases/20240101120000'
end
Notify on link change π
link '/etc/nginx/sites-enabled/app.conf' do
to '/etc/nginx/sites-available/app.conf'
notifies :reload, 'service[nginx]'
end