zoukankan      html  css  js  c++  java
  • [ansible]-ansible初始化mysql数据库

    0.目录结构

    $ tree mysql
    mysql
    ├── files
    │   └── web.sql
    ├── handlers
    │   └── main.yml
    ├── tasks
    │   └── main.yml
    ├── templates
    │   ├── client.cnf.j2
    │   ├── my.cnf.j2
    │   ├── mysql-clients.cnf.j2
    │   └── server.cnf.j2
    └── vars
    

    1.tasks内容

    - name: 01-install
      yum:
        name:  "{{ item }}"
        state: installed
      loop:
        - MySQL-python
        - mariadb
        - mariadb-server
      notify: 
        - remove_user 
        - remove_test
        - set_password 
        - create_user
    
    - name: 02-start
      service:
        name: mariadb
        state: started
    
    - name: 03-copy_conf
      template:
        src: "{{ item.src }}"
        dest: "{{ item.dest }}"
      loop:
        - { src: my.cnf.j2,            dest: /etc/my.cnf }
        - { src: client.cnf.j2,        dest: /etc/my.cnf.d/client.cnf }
        - { src: server.cnf.j2,        dest: /etc/my.cnf.d/server.cnf }
        - { src: mysql-clients.cnf.j2, dest: /etc/my.cnf.d/mysql-clients.cnf }
      notify:
        - restart_mysql
    
    - name: 04-copy_sql
      copy: 
        src: web.sql
        dest: /tmp/web.sql
      notify:
        - import_sql
    
    

    2.handlers内容

    - name: remove_user
      mysql_user:
        name: ''
        host_all: yes
        state: absent
    
    - name: remove_test 
      mysql_db: 
        name: test
        state: absent
    
    - name: set_password
      mysql_user:
        name: root
        password: '123456'
    
    - name: create_user
      mysql_user:
        login_user: root
        login_password: '123456'
        name: web
        password: oldboy123
        host: '172.16.1.%'
        priv: '*.*:ALL,GRANT'
        state: present
    
    - name: restart_mysql
      service:
        name: mariadb
        state: restarted 
    
    - name: import_sql
      mysql_db:
        login_user: root
        login_password: '123456'
        name: all
        state: import
        target: /tmp/web.sql
    
    
  • 相关阅读:
    豆瓣书籍数据采集
    动画精灵与碰撞检测
    图形
    模块
    对象
    函数
    列表与字典
    python 感悟
    SqlServer自动备份数据库(没有sql代理服务的情况下)
    关于AD获取成员隶属于哪些组InvokeGet("memberOf")的问题
  • 原文地址:https://www.cnblogs.com/alaska/p/12624917.html
Copyright © 2011-2022 走看看