diff --git a/changelogs/fragments/6138-fix-yarn-global.yml b/changelogs/fragments/6138-fix-yarn-global.yml new file mode 100644 index 0000000000..30203ead6c --- /dev/null +++ b/changelogs/fragments/6138-fix-yarn-global.yml @@ -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) diff --git a/plugins/modules/yarn.py b/plugins/modules/yarn.py index da9f9c79c3..02cfc4f8be 100644 --- a/plugins/modules/yarn.py +++ b/plugins/modules/yarn.py @@ -179,15 +179,11 @@ class Yarn(object): 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: @@ -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'] @@ -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, diff --git a/tests/integration/targets/yarn/tasks/run.yml b/tests/integration/targets/yarn/tasks/run.yml index 93a3d5bb55..0d7d6fb421 100644 --- a/tests/integration/targets/yarn/tasks/run.yml +++ b/tests/integration/targets/yarn/tasks/run.yml @@ -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 }}'