首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何为此cmd => mysql_secure_installation编写可挂起的Playbook

问如何为此cmd => mysql_secure_installation编写可挂起的Playbook
EN

Stack Overflow用户
提问于 2021-04-13 10:10:45
回答 1查看 215关注 0票数 1

如果我在Linux终端中运行这个cmd mysql_secure_installation,它将请求用户输入(y/n/其他选项)。如何在一本不可信的剧本中反映同样的情况?我尝试为这个cmd mysql_secure_installation使用shell模块,但不确定如何为用户输入编写,如下所示。

我的任务是使用Ansible Playbook安装MysqlDB。此外,我还附上了MYSQL安装的手动步骤。请帮我写一本同样的游戏手册。

提前谢谢。

代码语言:javascript
复制
#############################################################
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: <my-password>
Re-enter new password: <my-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 rpm -ivh mysql57-community-release-el7-11.noarch.rpm
 sudo yum install -y mysql-server
 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
 -------------------------------------------------------------------------------------------------------------
EN

回答 1

Stack Overflow用户

发布于 2021-04-14 07:20:12

是的,您可以检查角色是否存在,但是您也有已经存在的模块:

安装oracle的示例

代码语言:javascript
复制
- name: Install Oracle MySQL repo for RedHat Family.
  yum:
    name: "{{ redhat_mysql_repo }}"
    state: present
  when: ansible_os_family == "RedHat" and 'mysql' in group_names

另一个样本:

代码语言:javascript
复制
- name: Initialize MySQL 8.0 Insecure.
  shell: >
       mysqld --initialize-insecure
  when: ('8.0.' in mysql_cli_version.stdout) and (ansible_os_family == "RedHat")

你可以在8上看到这个例子

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67072854

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档