QT-DevOps / DevOpsIssues

This Repo will be used to demonstrate the Skills & Questions in DevOps
Apache License 2.0
27 stars 131 forks source link

Trying to write Ansible Playbook for MySQL Installation #1016

Open Pravin-Kumar-GitHub opened 3 years ago

Pravin-Kumar-GitHub commented 3 years ago

If I run this cmd mysql_secure_installation in the Linux terminal, it will be asking for user inputs (y/n/other options). How to reflect the same in an ansible playbook? I tried out using the shell module for the same, but not sure how to write for user inputs like below.

[My task is to install MySqlDB using Ansible Playbook. Also, I have attached my manual steps for MYSQL Installation. Could you please help me with writing an ansible playbook for the same.]

############################################################# Press y|Y for Yes, any other key for No: y Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1

Please set the password for root here. New password: Re-enter new password:

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y #############################################################

 MYSQL Installation:--

 sudo wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
 sudo yum localinstall mysql57-community-release-el7-11.noarch.rpm -y
 sudo yum install mysql-server -y
 sudo systemctl status mysqld
 sudo systemctl start mysqld

 mysql_secure_installation
 .....
 mysql -u root -p
 Enter password: <my-password>

 GRANT ALL ON root.* TO root@localhost WITH GRANT OPTION;
 FLUSH PRIVILEGES;
 exit
 sudo systemctl restart mysqld
 sudo systemctl status mysqld
 -------------------------------------------------------------------------------------------------------------