ansible-cmdb icon indicating copy to clipboard operation
ansible-cmdb copied to clipboard

Allow 'ansible-cmdb' wrapper to be a symlink

Open DanVanAtta opened this issue 3 years ago • 0 comments

Enhances 'ansible-cmdb' wrapper script to be able to find 'ansible-cmdb.py' when 'ansible-cmdb' is a symlink.

Currently the search paths around 'ansible-cmdb' are relative to the location of the symlink. We can use 'readlink -f' to instead follow the symlink and search from the actual location of 'ansible-cmdb'

The use-case where this comes up is we want to add 'ansible-cmdb' to the path. To do this we are creating a symlink from '/bin/ansible-cmdb' to its actual location. After this update, the command '/bin/ansible-cmdb' works as expected because the wrapper script follows the symlink.


This update is backward compatible. If '$0' is a file, then "readlink -f" will return the canonical file name of that file (existing behavior), otherwise if '$0' is a symlink then we recursively follow every symlink of '$0'.

For convenience, the man info on the '-f' flag:

     -f, --canonicalize
              canonicalize by following every symlink in every component of the given name recursively;
              all but the last component must exist

And the man info of 'readlink':

NAME
       readlink - print resolved symbolic links or canonical file names

DanVanAtta avatar Nov 10 '21 03:11 DanVanAtta