How can i control user inputs when a command is executing and ask me something for example :
sudo apt-get install mariadb-server
when you run this command in ubuntu it asked you please enter new password for mysql user root and then again it ask to enter password again for confirmation . how can i pass a variable for example mariadbpass to this command because everytime ansible run this hangs and failed so i have to login to servers and run manually this
dpkg --configure -a
to enter prompted password and its confirmation.
thank you
Here is the Solution : add this before installing mariadb 10 task in your playbook
- name: debconf asking for password
debconf:
name: maria-db-10.0
question: "{{ item }}"
vtype: password
value: "{{ mariadb_root_password }}"
with_items:
- mysql-server/root_password
- mysql-server/root_password_again
This is less of an ansible question and really a bash question. I'd suggest you take a look at this post and tie some of those into your playbook to do what you need.
The easiest for you in this case, is likely using a here string
tasks:
- shell: "apt-get install mariadb-server <<< $'password\otherprompts\n'"
sudo: true
来源:https://stackoverflow.com/questions/32861618/ansible-control-commands-when-need-users-input-when-executing