0

When my script starts, the shell asks me for the password for the module apt-get, and then again for ansible, because it has the option --ask-get-pass.

How do I enter the password only once for this script?

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
    Do you feel confident enough to store it as a variable that is asked for at the beginning of the script via read? – Cometsong May 22 '18 at 1:10
  • Good question. I run the script on my desktop. In this case (read), the password will be stored in the shell history? – dmin May 22 '18 at 1:31
  • But you don't get asked for the password multiple times for the three apt-get calls? – ilkkachu May 22 '18 at 7:05
2

The read command works in my case:

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 thanks for clue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.