加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – ansible回答mysql_secure_installation

发布时间:2020-12-16 01:17:03 所属栏目:安全 来源:网络整理
导读:我无法实现如何编写任务,即回答 mysql_secure_installation脚本问题. 我只有 shell: mysql_secure_installation '1111' executable=/bin/bash 并没有关于如何继续回答的想法. 解决这个问题的最佳方法是什么?提前致谢! 我认为你最好的办法是编写一个将重现m
我无法实现如何编写任务,即回答 mysql_secure_installation脚本问题.

我只有

shell: mysql_secure_installation  <<< '1111' executable=/bin/bash

并没有关于如何继续回答的想法.
解决这个问题的最佳方法是什么?提前致谢!

我认为你最好的办法是编写一个将重现mysql_secure_installation脚本的剧本(或更好的,改变你的mysql角色).有几个原因 :

>每次运行你的剧本时,剧本总会返回’已更改’,这不是你想要的
>编写任务更灵活:您可以根据设置添加,删除,更改和调整您想要执行的操作
>你可以在这个过程中学习

基本上,mysql_secure_installation执行此操作:

>设置root密码
>删除匿名用户
>删除根远程访问
>删除测试数据库

假设你已经设置了mysql_root_password,并添加了python-mysqldb,如下所示:

- name: Adds Python MySQL support on Debian/Ubuntu
      apt: pkg="python-mysqldb" state=present
      when: ansible_os_family == 'Debian'

    - name: Adds Python MySQL support on RedHat/CentOS
      yum: name=MySQL-python state=present
      when: ansible_os_family == 'RedHat'

这可以这样完成:

>设置root密码

- name: Sets the root password 
  mysql_user: user=root password="{{ mysql_root_password }}" host=localhost

>删除匿名用户

- name: Deletes anonymous MySQL server user for ansible_fqdn
  mysql_user: user="" host="{{ ansible_fqdn }}" state="absent"

- name: Deletes anonymous MySQL server user for localhost
  mysql_user: user="" state="absent"

>删除根远程访问

- name: Secures the MySQL root user for IPV6 localhost (::1)
  mysql_user: user="root" password="{{ mysql_root_password }}" host="::1"

- name: Secures the MySQL root user for IPV4 localhost (127.0.0.1)
  mysql_user: user="root" password="{{ mysql_root_password }}" host="127.0.0.1"

- name: Secures the MySQL root user for localhost domain (localhost)
  mysql_user: user="root" password="{{ mysql_root_password }}" host="localhost"

- name: Secures the MySQL root user for server_hostname domain
  mysql_user: user="root" password="{{ mysql_root_password }}" host="{{ ansible_fqdn }}"

>删除测试数据库

- name: Removes the MySQL test database
  mysql_db: db=test state=absent

这应该做到这一点.请注意,我快速浏览了一下系统中的mysql_secure_installation.我可能跳过了某些内容,或者其他版本中可能还有其他步骤. YMMV!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读