当我的脚本启动时,shell 会询问我该模块的密码apt-get
,然后再次询问我的密码ansible
,因为它有选项--ask-get-pass
.
如何为此脚本只输入一次密码?
sudo apt-add-repository -y ppa:ansible/ansible &&
sudo apt-get update &&
sudo apt-get install -y ansible &&
ansible-playbook --ask-become-pass playbook.yml
答案1
该read
命令适用于我的情况:
read -s -p "SUDO Password: " pass
echo "$pass" | sudo -S apt-add-repository -y ppa:ansible/ansible &&
sudo apt-get update &&
sudo apt-get install -y ansible &&
ansible-playbook --extra-vars "ansible_become_pass=$pass" playbook.yml
@Cometsong 谢谢你的线索