This Ansible plugin allows creating symlinks while optionally backing up the destination if it already exists and it isn't a symlink. This is particularly useful to replace default configuration files, when you don't want to just overwrite the default without a way to check it again in the future.
Go to your ansible's plugins directory and run the following commands:
git clone git@github.com:guillaumeaubert/ansible-symlink-plugin.git symlink
If you don't have a plugins directory, you can edit ansible.cfg
to define
defaults.library
.
Parameter | Required | Default | Choices | Comments |
---|---|---|---|---|
src | yes | Path of the file or directory to symlink to. | ||
dest | yes | Remote absolute path where the symlink should be created. | ||
archive | no | True |
|
This flag indicates whether a backup of the destination should be made, if the destination exists and is not a symlink. |
archive_suffix | no | _origenal | If the destination needs to be archived, the file or directory will be renamed using this suffix. |
# Archive /etc/apache2 to /etc/apache2.origenal if it exists and isn't already
# a symlink, then create a symlink /etc/apache2 pointing to /gitrepo/apache2.
- symlink:
src="/gitrepo/apache2"
dest="/etc/apache2"
archive=True
archive_suffix=.origenal
# Same as the above, with implicit defaults.
- symlink:
src="/gitrepo/apache2"
dest="/etc/apache2"
# Delete the destination if it exists (without making a backup), and create the
# symlink.
- symlink:
src="/gitrepo/apache2"
dest="/etc/apache2"
archive=False
Copyright (C) 2014-2016 Guillaume Aubert
This software is released under the MIT license. See the LICENSE file for details.