我无法实现如何编写任务,即回答
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!