LoginSignup
11
11

More than 5 years have passed since last update.

VagrantとAnsibleでMongoDB環境構築

Last updated at Posted at 2015-01-25

ホストOSにAnsibleをインストールしてVagrantのプロビジョニングでゲストOSにMongoDB環境を構築する。

ホストOSに必要なもの

  • VirtualBox
  • Vagrant
  • Python 2.4 以上
  • Ansible

Vagrantfile

Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
  config.vm.box = "chef/centos-6.5"
  config.vm.network "private_network", ip: "192.168.33.10"

  config.vm.provision :ansible do |ansible|
    ansible.playbook = "playbook.yml"
    ansible.inventory_path = "hosts"
    ansible.limit = 'all'
  end
end
  • AnsibleではSSHでログインするのでプライベートネットワークを設定しておく。
  • Vagrant1.5からはansible.limit = 'all'という記述がないとエラーになってしまうらしい。

hosts

hosts
[vagrant]
192.168.33.10

playbook

playbook.yml
- hosts: vagrant
  sudo: true
  user: vagrant
  tasks:
    - name: install python-selinux
      yum: pkg=libselinux-python state=latest
    - name: disable selinux
      selinux: state=disabled
    - name: copy mongodb.repo
      copy: src=mongodb.repo dest=/etc/yum.repos.d/mongodb.repo owner=root
    - name: install mongodb
      yum: pkg=mongodb-org
    - name: start mongodb
      service: name=mongod state=started
  • selinuxが有効になっているとansibleからroot権限で作業できないので、最初の2つのタスクでselinuxを無効にしている。
  • 3つめ以降のタスクはMongoDBのインストール手順に書いてある手順。

mongodb.repo

mongodb.repo
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1

VM起動

vagrant up

参考

11
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11