-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
file module always fails to create relative symlinks if force is not yes. #21401
Comments
During src path validation before link creation, dest joined with src. Nonsense path checked for existence. For absolute paths, os.path.join returned second parameter ie abs src path. Fix: Replaced os.path.join with os.path.abspath Testing: Existing integration testing sufficent, though some tests were successfully linking non-existing files without the force flag.
During src path validation before link creation, dest joined with src. Nonsense path checked for existence. For absolute paths, os.path.join returned second parameter ie abs src path. Fix: Replaced os.path.join with os.path.abspath Testing: Existing integration testing sufficent, though some tests were successfully linking non-existing files without the force flag.
During src path validation before link creation, dest joined with src. Nonsense path checked for existence. For absolute paths, os.path.join returned second parameter ie abs src path. Fix: Replaced os.path.join with os.path.abspath Testing: Existing integration testing sufficent, though some tests were successfully linking non-existing files without the force flag.
During src path validation before link creation, dest joined with src. Nonsense path checked for existence. For absolute paths, os.path.join returned second parameter ie abs src path. Fix: Replaced os.path.join with os.path.abspath Testing: Existing integration testing sufficent, though some tests were successfully linking non-existing files without the force flag.
Failed to commit fixes for tests that were linking non-existing dirs without force=yes
Files identified in the description: If these files are inaccurate, please update the |
Apologies for taking a long time to look into this. I have been able to look at it in the past few days, though, and I think this is working as expected. I'll summarize first and then give a longer explanation afterwards: I believe for your case, you have a directory tree like:
And you want to create a link so that the tree looks like this:
To achieve that you should use a playbook like the following:
The reason for this is that
If you look at the The documentation for the file module attempts to say this by saying that relative paths are not expanded:
but I think that it would be clearer if I mention that it works the same way as |
Fixes ansible#21401 Also sdd some more tests to validate file state=link creates a symlink which points to the file we intended.
Fixes #21401 Also sdd some more tests to validate file state=link creates a symlink which points to the file we intended.
Fixes ansible#21401 Also sdd some more tests to validate file state=link creates a symlink which points to the file we intended.
Fixes ansible#21401 Also sdd some more tests to validate file state=link creates a symlink which points to the file we intended.
Fixes ansible#21401 Also sdd some more tests to validate file state=link creates a symlink which points to the file we intended.
ISSUE TYPE
COMPONENT NAME
module/file
devel/lib/ansible/modules/files/file.py
ANSIBLE VERSION
CONFIGURATION
No changes made.
OS / ENVIRONMENT
cat /etc/centos-release
CentOS Linux release 7.3.1611 (Core)
SUMMARY
The file module cannot create symlinks: src and destination paths are concatinated and the result is used to check if the src exists.
STEPS TO REPRODUCE
Run the task below. The src is a directory that exists. In the dest only
dias-installer-4.5.0/installer_repository/
exists.EXPECTED RESULTS
A symlink to be created.
ACTUAL RESULTS
The output hints about the issue:
Note that I am asked if I want to create the link
dias-installer-4.5.0/installer_repository/dias-installer-4.5.0/release_repository.git
which is a path created by concatinating the dest and src path, essentially:dest/src
. I would not expect such a file to exist and I can only see the path is not created correctly. Perhaps the dest part was intended to be the first part of an absolute path?When I look into
https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/files/file.py
I find the following code:
In the first line,
relpath
, which originates as the dest or path argument, is joined with the src path. Exactly as I see in the output. In the last part of the code, the code fails if force is not set to yes.The text was updated successfully, but these errors were encountered: