Help us understand the problem. What is going on with this article?

AnsibleでMySQLインストール・ユーザ作成・データベース作成

More than 3 years have passed since last update.
  • Ubuntu 16.04 server LTS
  • MySQLサーバインストール
  • ユーザ作成
  • データベース作成
  • LAN(192.168.10.%)からのリモート接続を許可
mysql.yml
- hosts: all
  user: hoge
  become: yes
  vars:
    mysql_user: test_user
    mysql_password: test_password
    mysql_database: test_database
  tasks:
    - name: install MySQL packages
      apt: name={{ item }} state=installed
      with_items:
        - mysql-server
        - mysql-client
        - libmysqld-dev
        - libmysqlclient-dev
        - python-mysqldb
    - name: create mysql database
      mysql_db: name={{ mysql_database }} state=present
    - name: create mysql user
      mysql_user: name={{ mysql_user }} host={{ item }} password={{ mysql_password }} priv={{ mysql_database }}.*:ALL,GRANT state=present
      with_items:
        - localhost
        - 192.168.10.%
    - name: uncomment a line bind-address = 127.0.0.1
      replace: >
        dest=/etc/mysql/mysql.conf.d/mysqld.cnf
        regexp='^bind-address'
        replace='#bind-address'
    - name: start mysql
      service: name=mysql state=restarted enabled=yes

実行

リモートホスト"mysql-server"に対してPlaybookを実行する。Playbookを hosts: allにして、-iオプションで","をつけるとInventoryファイル無しで実行できる。

$ ansible-playbook -i "mysql-server," mysql.yml 

確認

"mysql-server"にリモート接続できることを確認。

$ mysql -h mysql-server -u test_user -p
Enter password:***** <test_passwordを入力>

mysql>use test_database;
Database changed

mysql>quit;
Bye
$

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした