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

fix resolve tilde in file paths (fixes #161) #162

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

antonc42
Copy link

SUMMARY

The libvirt_qemu connection module uses QEMU guest agent to copy files
and run commands on the remote host. Ansible uses the '~/' symbolic path
to the user's home directory for many commands and file paths.
Unfortunately, since QEMU guest agent doesn't run in a shell, it doesn't
resolve the '~/' path to the user's homedir.

Instead, the Ansible paths end up at '/~/' in the remote host. This
breaks some assumptions for some modules about the path to the Ansible
files. Some modules use the resolved homedir path and fail to find any
files in that location.

This fix first resolves the remote user homedir with a QEMU guest
command, caches the result, and then replaces '~/' found in any command
or remote file paths with the resolved absolute path to the user's
homedir.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

community.libvirt.libvirt_qemu connection plugin

ADDITIONAL INFORMATION

I've tested this patch with playbooks that use many different Ansible modules and it seems to work in all the ones I tested, including the copy module that was having issues in #161.

The libvirt_qemu connection module uses QEMU guest agent to copy files
and run commands on the remote host. Ansible uses the '~/' symbolic path
to the user's home directory for many commands and file paths.
Unfortunately, since QEMU guest agent doesn't run in a shell, it doesn't
resolve the '~/' path to the user's homedir.

Instead, the Ansible paths end up at '/~/' in the remote host. This
breaks some assumtions for some modules about the path to the Ansible
files. Some modules use the resolved homedir path and fail to find any
files in that location.

This fix first resolves the remote user homedir with a QEMU guest
command, caches the result, and then replaces '~/' found in any command
or remote file paths with the resolved absolute path to the user's
homedir.
@leegarrett
Copy link

This looks good to me, it fixes the issue #161. Can we get this merged?

@csmart
Copy link
Collaborator

csmart commented Jan 27, 2024

Hi @antonc42 thanks for the contribution! I've been trying to replicate this and finally did on Ubuntu, see my comment in the issue here #161 (comment)

I think it may be a problem with dash being the default shell, it seems to work as expected if I switch the default shell to bash. Would appreciate if you can see if that also works for you.

In terms of a patch, I would probably prefer to see if there's another way to solve it rather than using specific Linux commands and regex, if possible. Not sure if something like os.path.expanduser can help on the remote side. However if we do have to use commands, then we may need some if checks for the OS as I'm not sure that the patch as it is would work on Windows guests.

/cc @leegarrett

@leegarrett leegarrett mentioned this pull request Apr 17, 2024
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.

None yet

3 participants