Skip to content
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

Bugfix for #17492 "Do not prepend PWD when path is in form user@server:path or server:path" #118

Merged
merged 1 commit into from
Mar 5, 2021

Conversation

pneerincx
Copy link
Contributor

SUMMARY

This fixes the old bug #17492: "Do not prepend PWD when path is in form user@server:path or server:path" (again).
Fix was already in the ansible/ansible repo pull request 33998 as of December 2017, but never got merged.

There are several instances where the _get_absolute_path function is called. This should only happen for relative paths on a local file system and hence

  • not for paths on a remote server
  • nor for absolute paths.

The synchronize.py plugin checked before calling this function whether it was necessary to call _get_absolute_path.
It should not convert a path to an absolute path when it:

  • contains a colon (path on remote server) or
  • starts with a slash forward (absolute path).

In some cases the code would perform both checks and in some it failed to check for remote paths. This results in ${PWD} getting prepended to the remote path leading to something like /path/to/PWD/user@server:/path/to/what/needs/to/be/synced.

In this pull request the the two checks for remote paths and absolute paths are relocated to the _get_absolute_path function to remove code redundancy and to ensure the paths are always checked before trying to convert a local relative path into an absolute one.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

synchronize plugin

ADDITIONAL INFORMATION

Bug happens when using synchronize in pull mode. E.g.

synchronize: mode=pull src=rsync:https://somehost.com/path/ dest=/some/absolute/path/

will fail in any Ansible version with something like:

failed rsync from ${PWD}rsync:https://somehost.com/path/

@maxamillion
Copy link
Collaborator

Thank you for the contribution! This is great and the change looks good, would you mind adding a couple tests cases to tests/integration/targets/synchronize/tasks/main.yml?

Thank you!

@pneerincx
Copy link
Contributor Author

I've looked at the code for the tests, but have a hard time figuring out how to make this work. All the current tests in tests/integration/targets/synchronize/tasks/main.yml run rsync with both src and dest on a local machine. Hence the r in rsync is never used. The bug described here only occurs when either src or dest is a remote path in the form user@server:/path/to/data. I've tried to simulate a remote path on the local machine with:

  1. {{ lookup('env', 'USER') }}@localhost:{{ output_dir }}/foo.txt
  2. {{ ansible_user }}@localhost:{{ output_dir }}/foo.txt
  3. localhost:{{ output_dir }}/foo.txt

The first option fails because apparently ${USER} is undefined in the test environment as reported by ansible-test env
The second option also does work as {{ ansible_user }} does not exist in the test environment either.
Leaving the user out and only using localhost: will fail if the test environment does not have SSH login with public-private key pairs configured resulting in a password prompt. I can type that password on my laptop, but this won't fly in an automated CI environment...

@maxamillion
Copy link
Collaborator

!rebuild

@maxamillion
Copy link
Collaborator

/rebuild

@maxamillion
Copy link
Collaborator

Closing and reopening to rekick CI since the last time this one ran was on the old CI system

@maxamillion maxamillion closed this Mar 5, 2021
@maxamillion maxamillion reopened this Mar 5, 2021
@maxamillion maxamillion added the gate Gate PR in Zuul CI (Obsolete: Please set "mergeit" instead of "gate") label Mar 5, 2021
@maxamillion
Copy link
Collaborator

This is great, thanks! Approved and merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gate Gate PR in Zuul CI (Obsolete: Please set "mergeit" instead of "gate")
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Synchronize: Remote source path is prefixed with current working directory
2 participants