我使用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