我使用ansible 1.9并想运行两个命令。我尝试了好几种变化:用Ansible运行几个命令
- name: npm build
command: npm run build
args:
chdir: "{{ app_dir }}"
- name: clean up
shell: sed_index.sh
args:
chdir: "{{ app_dir }}"
在运行,我得到以下错误:
"stderr": "/bin/sh: 1: npm: not found"
然而
npm run build
,当我登录到服务器并在运行正常工作APP_DIR。
我也试过:
- name: npm install and clean
command: "{{ item }} chdir={{ app_dir }}"
with_items:
- npm run build
- sed_index.sh
我再次得到错误未找到NPM。
如果我注释掉npm run build命令,在下面的'cd dist'命令上运行sed_index脚本时发现错误,说'dist'找不到。
sed_index.sh
#!/usr/bin/env bash
cd dist
sed -i 's|=static/css/font-awesome.min.css rel=stylesheet>|=/app/static/css/font-awesome.min.css rel=stylesheet>|g' index.html
任何想法?
我添加了npm run build到服务器上的shell脚本,然后用命令“{{app_dir}}/npm_build.sh”运行它,但是我得到了一个npm:command not found错误。 npm全球安装在服务器上,所以我不知道为什么这将是 – proximacentauri
我已经回答了这个问题,阅读答案。 – techraf
@techrat,对不起,但我不明白你有回答我的问题? npm确实存在于服务器上,我希望我应该能够从任何目录运行它。关于sed_index。嘘,dist目录存在,但我可能需要运行其中的所有命令而不是服务器上的脚本,因为我不知道如何让脚本识别它当前在服务器上的目录。 – proximacentauri