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

[PR #6138/3d67f518 backport][stable-6] Fix Yarn global not working without explicit executable path #6141

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/6138-fix-yarn-global.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- yarn - fix ``global=true`` to not fail when `executable` wasn't specified (https://github.com/ansible-collections/community.general/pull/6132)
14 changes: 7 additions & 7 deletions plugins/modules/yarn.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,11 @@ def __init__(self, module, **kwargs):
self.registry = kwargs['registry']
self.production = kwargs['production']
self.ignore_scripts = kwargs['ignore_scripts']
self.executable = kwargs['executable']

# Specify a version of package if version arg passed in
self.name_version = None

if kwargs['executable']:
self.executable = kwargs['executable'].split(' ')
else:
self.executable = [module.get_bin_path('yarn', True)]

if kwargs['version'] and self.name is not None:
self.name_version = self.name + '@' + str(self.version)
elif self.name is not None:
Expand Down Expand Up @@ -328,7 +324,6 @@ def main():
version = module.params['version']
globally = module.params['global']
production = module.params['production']
executable = module.params['executable']
registry = module.params['registry']
state = module.params['state']
ignore_scripts = module.params['ignore_scripts']
Expand All @@ -345,9 +340,14 @@ def main():
if state == 'latest':
version = 'latest'

if module.params['executable']:
executable = module.params['executable'].split(' ')
else:
executable = [module.get_bin_path('yarn', True)]

# When installing globally, use the defined path for global node_modules
if globally:
_rc, out, _err = module.run_command([executable, 'global', 'dir'], check_rc=True)
_rc, out, _err = module.run_command(executable + ['global', 'dir'], check_rc=True)
path = out.strip()

yarn = Yarn(module,
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/targets/yarn/tasks/run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@
that:
- yarn_install_old_package is changed

- name: 'Again but without explicit executable path'
yarn:
path: '{{ remote_tmp_dir }}'
name: left-pad
version: 1.1.0
state: present
environment:
PATH: '{{ yarn_bin_path }}:{{ node_bin_path }}:{{ ansible_env.PATH }}'

- name: 'Upgrade old package'
yarn:
path: '{{ remote_tmp_dir }}'
Expand Down