0
votes

Versions - Ubuntu 16.04.2, Angular CLI 1.1.0, Ansible 2.3.0.0, and Python 2.7.12.

I'm trying to run ng build locally to create a build which will ultimately be copied to a remote server. For some reason the ng command is not being recognized when being run inside ansible.

Angular CLI is installed globally and ng works everywhere.

Here is the play:

    - name: "Building"
      shell: chdir="~/project/dir/" ng build

Here is the exact error from Ansible:

fatal: [localhost]: FAILED! => {"changed": true, "cmd": "ng build", "delta": >"0:00:00.001310", "end": "2017-05-31 22:59:34.397388", "failed": true, "rc": >127, "start": "2017-05-31 22:59:34.396078", "stderr": "/bin/sh: 1: ng: not >found", "stderr_lines": ["/bin/sh: 1: ng: not found"], "stdout": "", >"stdout_lines": []}

Any ideas?

3

3 Answers

2
votes

Try something like this. Note, I am using NVM to manage node version.

tasks:
- name: "Build myapp"
  command: ng build --prod --aot --env:prod
  args:
    chdir: /home/jeff/myapp/client/
  environment:
    PATH: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/home/jeff/.nvm/versions/node/v7.9.0/bin/
0
votes

I am not familiar with Angular, but if ng is a shell function rather than an executable, then you can try rewrite to:

- name: "Building" shell: "bash -lc 'ng build'" args: chdir="~/project/dir/"

0
votes

Use full path to the ng executable.

There is no such situation as "something is installed globally" in Unix/Linux/Windows. Either an executable is in the directories defined in the PATH variable, or not.

Ansible calls a non-interactive shell session and not all rc-files are sourced (see for example man bash).