Skip to content

Conversation

@DanVanAtta
Copy link

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

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant