AnsibleでmariaDBをインストールする

今さらですが最近Ansibleの勉強を始めたので、環境を用意していろいろ試そうと思います。試した結果をこのブログに記載します。

今日は、事前に用意した仮想マシンmariaDBを入れるだけというシンプルをやったのでメモっておきます。

 

ホストPCはcentos7とし、ansibleを入れてます。

仮想マシンにはvagrant cloudから取得したcentos7を使用します。

 

まずはPlaybookを作成します。
mysql.ymlという名前でplaybookを作成します。

以下の例はmariaDBのインストールを行い、設定ファイルをコピーした上で、サービス起動までの作業を記述しています。

---

- name: Configure DBServer with mariadb

  hosts: Aqours

  become: True

  tasks:

    - name: install mariadb

      yum: name=mariadb state=installed



    - name: install mariadb-server

      yum: name=mariadb-server state=installed



    - name: copy mariadb config file

      copy: src=/home/config/my.cnf dest=/etc/my.cnf.



    - name: service run mariadb

      service: name=mariadb  state=started enabled=yes

 

作ったファイルを以下のコマンドでインストールする。

ansible-playbook mysql.yml

 

完了すると以下のようになります。

[root@localhost centos]# ansible-playbook mysql.yml

[DEPRECATION WARNING]: [defaults]hostfile option, The key is misleading as it can also be

 a list of hosts, a directory or a list of paths . This feature will be removed in

version 2.8. Deprecation warnings can be disabled by setting deprecation_warnings=False

in ansible.cfg.



PLAY [Configure DBServer with mariadb] ***************************************************



TASK [Gathering Facts] *******************************************************************

ok: [Aqours]



TASK [install mariadb] *******************************************************************

changed: [Aqours]



PLAY RECAP *******************************************************************************

Aqours                     : ok=2    changed=1    unreachable=0    failed=0


これであと、gitとかと連携して設定ファイルなどをそっちからcloneできるようにしたいと思います。