如何通过ansible playbook执行mysql_secure_installation?

分享于 

2分钟阅读

互联网

  繁體

问题:

我成功使用playbook安装了Apache Mysql/ Mariadb和PHP,如何使用ansible执行mysql_secure_installation


答案1:

以下是我执行的步骤:


 # mysql_secure_installation


- name: Update MariaDB root password


 mysql_user: name=root host={{item}} password={{mysql_root_password}}


 with_items:


 - 127.0.0.1


 - ::1


 - localhost



- name: Set ~/.my.cnf file


 template: src=dotmy.cnf.j2 dest=/root/.my.cnf mode=0600



 # mysql_secure_installation


- name: Delete anonymous MySQL user


 mysql_user: name="" host={{item}} state=absent


 with_items:


 - localhost


 - "{{ansible_nodename}}"



 # mysql_secure_installation


- name: Delete Hostname based MySQL user


 mysql_user: name=root host="{{ansible_nodename}}" state=absent



 # mysql_secure_installation


- name: Remove MySQL test database


 mysql_db: name=test state=absent



你必须自己决定如何创建mysql_root_password


答案2:

通过Ansible直接执行mysql_secure_installation的强化步骤,而不是通过Ansible直接执行mysql_secure_installation是一个很好的实践。

mysql_secure_installation执行以下操作:

  • 设置root密码
  • 删除匿名用户
  • 删除root远程访问
  • 删除测试数据库
  • 
    - name: test database is absent
    
    
     mysql_db: name=test state=absent
    
    
     when: mysql_remove_test_database
    
    
    
    


    相关文章