2.25.1.0-b194
amannijhawan
tagged this
16 Jan 00:53
Summary: We try to create the directory that overrides the symlink that was created by root. This fails the playbook. The reason we try to do this is because the exist check fails on symlinks that point to invalid files. To fix this we added follow: false here that checks if symlink exists but does not check if it is valid. Test Plan: Verified on the node that the issue was due to invalid symlink ``` [yugabyte@yb-cloud-c-3cbcuz7r4jgvzgepizfvp7ue4m-n6 ~]$ ls -lahtr /home/yugabyte/cores -lahtr lrwxrwxrwx. 1 yugabyte yugabyte 13 Nov 20 17:13 /home/yugabyte/cores -> /mnt/d0/cores >>> import os >>> os.path.exists("/home/yugabyte/cores") False >>> ``` Tested by localy reproducing the issue ``` - name: Test symlink behavior with stat hosts: localhost gather_facts: false tasks: - name: Create a symlink to a non-existent directory file: src: "/tmp/non_existent_target" dest: "/tmp/test_symlink" force: true state: link - name: Create a directory for testing file: path: "/tmp/existing_dir" state: directory - name: Create a symlink to the existing directory file: src: "/tmp/existing_dir" dest: "/tmp/valid_symlink" state: link - name: Stat non-existent symlink without following stat: path: "/tmp/test_symlink" follow: false register: invalid_symlink_stat - name: Display results for non-existent symlink debug: msg: "{{ invalid_symlink_stat }}" - name: Stat valid symlink and follow target stat: path: "/tmp/valid_symlink" register: valid_symlink_stat - name: Display results for valid symlink debug: msg: "{{ valid_symlink_stat.stat.exists }} {{ invalid_symlink_stat.stat.exists }}" ``` running it locally. ``` centos@dev-server-anijhawan-4 test_ansible]$ ansible-playbook -v test.yml Using /etc/ansible/ansible.cfg as config file [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' PLAY [Test symlink behavior with stat] ************************************************************************************************************************************************************************************************** TASK [Create a symlink to a non-existent directory] ************************************************************************************************************************************************************************************* [WARNING]: Cannot set fs attributes on a non-existent symlink target. follow should be set to False to avoid this. ok: [localhost] => {"changed": false, "dest": "/tmp/test_symlink", "src": "/tmp/non_existent_target"} TASK [Create a directory for testing] *************************************************************************************************************************************************************************************************** ok: [localhost] => {"changed": false, "gid": 1001, "group": "centos", "mode": "0775", "owner": "centos", "path": "/tmp/existing_dir", "secontext": "unconfined_u:object_r:user_tmp_t:s0", "size": 6, "state": "directory", "uid": 1000} TASK [Create a symlink to the existing directory] *************************************************************************************************************************************************************************************** ok: [localhost] => {"changed": false, "dest": "/tmp/valid_symlink", "gid": 1001, "group": "centos", "mode": "0777", "owner": "centos", "secontext": "unconfined_u:object_r:user_tmp_t:s0", "size": 17, "src": "/tmp/existing_dir", "state": "link", "uid": 1000} TASK [Stat non-existent symlink without following] ************************************************************************************************************************************************************************************** ok: [localhost] => {"changed": false, "stat": {"atime": 1736978358.3861384, "attr_flags": "", "attributes": [], "block_size": 4096, "blocks": 0, "charset": "unknown", "ctime": 1736978358.3851383, "dev": 2050, "device_type": 0, "executable": false, "exists": true, "gid": 1001, "gr_name": "centos", "inode": 51644557, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": true, "isreg": false, "issock": false, "isuid": false, "lnk_source": "/tmp/non_existent_target", "lnk_target": "/tmp/non_existent_target", "mimetype": "unknown", "mode": "0777", "mtime": 1736978358.3851383, "nlink": 1, "path": "/tmp/test_symlink", "pw_name": "centos", "readable": false, "rgrp": true, "roth": true, "rusr": true, "size": 24, "uid": 1000, "version": null, "wgrp": true, "woth": true, "writeable": false, "wusr": true, "xgrp": true, "xoth": true, "xusr": true}} TASK [Display results for non-existent symlink] ***************************************************************************************************************************************************************************************** ok: [localhost] => { "msg": { "changed": false, "failed": false, "stat": { "atime": 1736978358.3861384, "attr_flags": "", "attributes": [], "block_size": 4096, "blocks": 0, "charset": "unknown", "ctime": 1736978358.3851383, "dev": 2050, "device_type": 0, "executable": false, "exists": true, "gid": 1001, "gr_name": "centos", "inode": 51644557, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": true, "isreg": false, "issock": false, "isuid": false, "lnk_source": "/tmp/non_existent_target", "lnk_target": "/tmp/non_existent_target", "mimetype": "unknown", "mode": "0777", "mtime": 1736978358.3851383, "nlink": 1, "path": "/tmp/test_symlink", "pw_name": "centos", "readable": false, "rgrp": true, "roth": true, "rusr": true, "size": 24, "uid": 1000, "version": null, "wgrp": true, "woth": true, "writeable": false, "wusr": true, "xgrp": true, "xoth": true, "xusr": true } } } TASK [Stat valid symlink and follow target] ********************************************************************************************************************************************************************************************* ok: [localhost] => {"changed": false, "stat": {"atime": 1736978358.9851966, "attr_flags": "", "attributes": [], "block_size": 4096, "blocks": 0, "charset": "binary", "ctime": 1736978358.9821963, "dev": 2050, "device_type": 0, "executable": true, "exists": true, "gid": 1001, "gr_name": "centos", "inode": 51644558, "isblk": false, "ischr": false, "isdir": false, "isfifo": false, "isgid": false, "islnk": true, "isreg": false, "issock": false, "isuid": false, "lnk_source": "/tmp/existing_dir", "lnk_target": "/tmp/existing_dir", "mimetype": "inode/symlink", "mode": "0777", "mtime": 1736978358.9821963, "nlink": 1, "path": "/tmp/valid_symlink", "pw_name": "centos", "readable": true, "rgrp": true, "roth": true, "rusr": true, "size": 17, "uid": 1000, "version": null, "wgrp": true, "woth": true, "writeable": true, "wusr": true, "xgrp": true, "xoth": true, "xusr": true}} TASK [Display results for valid symlink] ************************************************************************************************************************************************************************************************ ok: [localhost] => { "msg": "True True" } PLAY RECAP ****************************************************************************************************************************************************************************************************************************** localhost : ok=7 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ``` Reviewers: muthu, daniel, nsingh Reviewed By: muthu, nsingh Subscribers: yugaware Differential Revision: https://phorge.dev.yugabyte.com/D41265