Stan Luo
Stan Luo

Reputation: 3889

Ansible cannot run global npm package

When executing the following scripts where 'bappo-migrate' is a global npm package:

- name: Install migration-cli globally
  npm:
    name: '@bappo/migration-cli'
    global: yes

- name: Run new migration scripts
  command: bappo-migrate upgrade chdir={{homeDir}}/bappo/bappo-api/mongo_migrations
  environment:
    PATH: '{{homeDir}}/.npm-global/bin:$PATH'

Ansible throws error:

{  
   "changed":false,
   "cmd":"bappo-migrate upgrade",
   "msg":"[Errno 2] No such file or directory",
   "rc":2
}

Cannot understand the error message - can confirm the directory exists and have tried manually executing the above commands, everything works fine.

Upvotes: 1

Views: 652

Answers (1)

Stan Luo
Stan Luo

Reputation: 3889

Environment setting should be:

environment:
    PATH: "{{ ansible_env.PATH }}:{{homeDir}}/.npm-global/bin"

As ansible can't deal with $PATH in environment correctly.

Here is Source.

Upvotes: 1

Related Questions