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

Expand user home on galaxy install src #70942

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/70942_galaxy_install.yml
@@ -0,0 +1,2 @@
bugfixes:
- galaxy - expand ``~`` (user home) from role src (https://github.com/ansible/ansible/pull/70942/).
3 changes: 3 additions & 0 deletions docs/docsite/rst/galaxy/user_guide.rst
Expand Up @@ -272,6 +272,9 @@ Use the following example as a guide for specifying roles in *requirements.yml*:

# from locally cloned git repository (file:// requires full paths)
- src: file:///home/bennojoy/nginx

# from locally cloned repository
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wording might be confusing since we have particular syntax for repos. The example above was recently changed 7762741.

# from local path

is maybe clearer

- name: ~/src/bennojoy/nginx

# from GitHub
- src: https://github.com/bennojoy/nginx
Expand Down
3 changes: 2 additions & 1 deletion lib/ansible/galaxy/role.py
Expand Up @@ -38,6 +38,7 @@
from ansible.module_utils.urls import open_url
from ansible.playbook.role.requirement import RoleRequirement
from ansible.utils.display import Display
from ansible.utils.path import unfrackpath

display = Display()

Expand All @@ -64,7 +65,7 @@ def __init__(self, galaxy, api, name, src=None, version=None, scm=None, path=Non

self.name = name
self.version = version
self.src = src or name
self.src = unfrackpath(src or name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could be using unfrackpath on a URL, git repo, or something that provides an absolute path prefixed with file://. This would break those scenarios since we automatically prepend a base dir in unfrackpath.

>>> from ansible.utils.path import unfrackpath
>>> unfrackpath('https://github.com/')
'/home/shertel/ansible/https:/github.com'
>>> unfrackpath('file:///path')
'/home/shertel/ansible/file:/path'
>>> unfrackpath('git+file:///path')
'/home/shertel/ansible/git+file:/path'

We might be able to move this somewhere that's only supposed to handle directories, or your original os.path.expanduser() may be a better choice.

This definitely needs tests.

self.scm = scm
self.paths = [os.path.join(x, self.name) for x in galaxy.roles_paths]

Expand Down