Reputation: 534
I have a machine that has zsh installed. I created the following script to make some installs:
Installs made
# Install NVM
sudo curl https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
## Reload shell to start using nvm
. ~/.zshrc
. ~/.nvm/nvm.sh
nvm install 0.12
Now I want to connect to the instance and run ansible-playbook that will start the following script:
sh-script.sh
npm install aws-sdk
node create-queue.js $machine_name
node create-queue.js $machine_name
When running the playbook I get the following errors: line 28: npm: command not found -- line 32: node: command not found -- line 33: node: command not found.
When I ssh to the instance and run "node" or "npm" I get valid response and desired condition. The ansible-playbook is very simple:
ansible
- hosts: tag_Name_TestInstance
tasks:
- name: Run Script
shell: /home/ubuntu/sh-script.sh '{{ machine_name }}'
Upvotes: 1
Views: 12824
Reputation: 191
the best way IMHO to solve this is to add an additional bin path to the ansible env.
- name: Install aws-sdk
command: /opt/node/bin/npm "something"
environment:
PATH: "{{ ansible_env.PATH }}:/opt/node/bin"
or you could use the native ansible npm function
description: Install "aws-sdk" node.js package.
- npm: name=aws-sdk path=/app/location
environment:
PATH: "{{ ansible_env.PATH }}:/opt/node/bin"
and two other tasks to run the node js script. That way you could have also more info about what is going on.
good luck
Upvotes: 4
Reputation: 1179
This is likely because npm and node have not been added to your $PATH
. The shell module will use /bin/sh
to run your command.
If you want to run the script in zsh, try adding the shebang with the path to your zsh installation eg: !#/usr/local/bin/zsh
Upvotes: 0