ansible通过剧本管理mysql

ansible 编写mysql_use模块的使用
今天使用ansible安装管理mariadb数据库的时候,碰到问题,在网上找不到对应的解决办法。然后自己查资料,终于写出,
查阅资料:编写如下脚本

[root@manager-161 playbook]# cat  mysql.yaml    
- hosts: mysql
  tasks:

    - name: install mariadb
      yum: name=mariadb-devel,mariadb-server state=installed

    - name: install python-devel pip
      yum: name=python-devel,python2-pip state=installed

    - name: shell mtsql-python
      shell: 'pip install MySQL-python'

    - name: statr mariadb
      service: name=mariadb state=started enabled=yes

    - mysql_user:
        user: root
        password: sf123
        update_password: always

    - name: create wordpress
      mysql_db:
        name: 'root'
        login_host: 'localhost'
        login_password: 'zsf123'
        name: 'wordpress'
        state: 'present'

    - mysql_user:
        user: 'root'
        login_host: 'localhost'
        login_password: 'zsf123'
        user: 'zzsf'
        password: 'zsf124'
        priv: '*.*:ALL'
        state: present

    - mysql_user:
        user: 'root'
        login_host: 'localhost'
        login_password: 'zsf123'
        user: 'zzsf'
        password: 'zsf124'
        priv: '*.*:ALL'
        host_all: yes
        state: present

    - mysql_db:
        user: 'root'
        login_host: 127.0.0.1
        login_password: zsf123
        name: lt
        state: present

#mariadb安装之后没有密码,我们必须先更改root的密码
然后mysql需要安装mysql-python的模块
yum -y install python-devel,python2-pip
pip install mysql

转载于:https://blog.51cto.com/13447608/2280880

你可能感兴趣的:(ansible通过剧本管理mysql)