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

yarn: #5829 causes "global dir" and "global: GTAGS not found." error #6132

Closed
1 task done
Chomtana opened this issue Mar 3, 2023 · 6 comments · Fixed by #6138
Closed
1 task done

yarn: #5829 causes "global dir" and "global: GTAGS not found." error #6132

Chomtana opened this issue Mar 3, 2023 · 6 comments · Fixed by #6138
Labels
bug This issue/PR relates to a bug language module module packaging plugins plugin (any type)

Comments

@Chomtana
Copy link

Chomtana commented Mar 3, 2023

Summary

I am doing yarn global add ... in ansible-core version 2.14.3 and experiencing this error that doesn't happen in the previous 2.14.2 version. I have investigated that the cause is from the pull request #5829

TASK [install_software : Install graph cli] ************************************
fatal: [node]: FAILED! => {"changed": false, "cmd": "global dir", "msg": "global: GTAGS not found.", "rc": 3, "stderr": "global: GTAGS not found.\n", "stderr_lines": ["global: GTAGS not found."], "stdout": "", "stdout_lines": []}

That is because it can't detect yarn as an executable in this line of code.

https://github.com/ansible-collections/community.general/pull/5829/files#diff-baebe07da57aab76abf01ac7c4b8d6730b6111f18813e93a898a217c752568d3R343

So it runs global dir instead of the expected yarn global dir command.

Issue Type

Bug Report

Component Name

yarn

Ansible Version

$ ansible --version

ansible [core 2.14.3]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.10/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = False

Community.general Version

$ ansible-galaxy collection list community.general

# /usr/local/lib/python3.10/dist-packages/ansible_collections
Collection        Version
----------------- -------
community.general 6.4.0

Configuration

$ ansible-config dump --only-changed

CONFIG_FILE() = None
HOST_KEY_CHECKING(env: ANSIBLE_HOST_KEY_CHECKING) = False

OS / Environment

A docker container running Ubuntu 22.04 image

Steps to Reproduce

- name: "Install graph cli"
  yarn:
    name: '@graphprotocol/graph-cli'
    version: '0.42.3'
    global: true

Expected Results

It should run yarn global dir

Actual Results

It runs "global dir" instead (missing yarn)

TASK [install_software : Install graph cli] ************************************
fatal: [node]: FAILED! => {"changed": false, "cmd": "global dir", "msg": "global: GTAGS not found.", "rc": 3, "stderr": "global: GTAGS not found.\n", "stderr_lines": ["global: GTAGS not found."], "stdout": "", "stdout_lines": []}

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link
Collaborator

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug language module module packaging plugins plugin (any type) labels Mar 3, 2023
@felixfontein
Copy link
Collaborator

CC @sargunv @russoz

@sargunv
Copy link
Contributor

sargunv commented Mar 3, 2023

Ah I see, this line executes before the path to Yarn is identified from the PATH if it wasn't passed explicitly:

module.run_command([executable, 'global', 'dir'], check_rc=True)

@sargunv
Copy link
Contributor

sargunv commented Mar 3, 2023

Pulling this logic out of the initializer so it runs before the above line should fix it:

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

@sargunv
Copy link
Contributor

sargunv commented Mar 3, 2023

And since the tests all explicitly set the executable, this wasn't caught:

    - name: 'Global install binary with explicit version (older version of package)'
      yarn:
        global: true
        executable: '{{ yarn_bin_path }}/yarn'  # THIS LINE
        name: prettier
        version: 2.0.0
        state: present
      environment:
        PATH: '{{ node_bin_path }}:{{ ansible_env.PATH }}'
      register: yarn_global_install_old_binary

Will file a PR soon, but a workaround to get y'all unblocked might work something like this:

    - name: example
      yarn:
        global: true
        executable: "{{ lookup('lines', 'which yarn') }}"  # THIS LINE
        name: prettier
        version: 2.0.0
        state: present

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug language module module packaging plugins plugin (any type)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants