2

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

Arash Shams
  • 186
  • 1
  • 2
  • 12

2 Answers2

3

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
Arash Shams
  • 186
  • 1
  • 2
  • 12
2

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
Community
  • 1
  • 1
trmiller
  • 183
  • 5
  • i found another answer that is using debconf module in ansible if i success with debconf i will write it down here – Arash Shams Oct 03 '15 at 11:37