![](/img/trans.png)
[英]In a shell script: redirect echo shell commands as they are executed
[英]Skip shell commands when script is executed by Ansible
我有一個 shell 腳本可以做很多事情。 有一段驗證 GitHub package 注冊表。 此部分提示輸入用戶名和密碼。 當我使用 Ansible 執行 bash 腳本時,它卡在那里並顯示一條消息“升級成功”。 我要做的是在 ansible 中定義注冊表登錄,這當然是直截了當的。 那不是問題。 我遇到的問題是,當通過 ansible 運行腳本時,我希望跳過 bash 腳本中的 GitHub 注冊表命令。 就像是:
if [[ "$ANSIBLE" == "true" ]]; then
skip
fi
知道如何實現嗎?
可以為 Ansible 任務設置環境。 例如
- name: Shell script that does a lot of stuff
command: my_script.sh
environment:
my_script_in_ansible: "true"
然后在腳本中使用變量。 例如
ANSIBLE=${my_script_in_ansible:-false}
if [[ "$ANSIBLE" == "true" ]]; then
skip
fi
避免環境名稱的潛在沖突是個好主意。
(未測試)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.