当执行以下脚本时,其中“ bappo-migrate”是全局npm软件包:

- 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引发错误:

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


无法理解错误消息-可以确认目录存在,并尝试手动执行上述命令,一切正常。

最佳答案

环境设置应为:

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


不能正确处理$PATH中的environment

这是Source

07-25 20:44