Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the full path of the symlink target in Ansible

Tags:

ansible

How do I get the full path of a symlink target in Ansible? I'm trying to cleanup a folder--delete files older than x number of days but I don't want to remove the target of a particular file symlink. My plan is to get the symlink target and then use the value as an exclude target when using the find module.

The symlink target changes from time to time. I tried using the stat module but it doesn't solve my requirement.

like image 262
FrancisV Avatar asked Jan 02 '23 15:01

FrancisV


1 Answers

stat module returns lnk_source and lnk_target which should do the trick.


Pay attention to confusing names:

  • lnk_source => Target of the symlink normalized for the remote filesystem
  • lnk_target => Target of the symlink. Note that relative paths remain relative

For the actual SOURCE of the symlink, well, it's just path.

like image 177
Konstantin Suvorov Avatar answered Jan 13 '23 05:01

Konstantin Suvorov