7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

vagrant上のcentosにansibleでdocker-ceをインストールする

Posted at

ansibleを勉強していく上でvagrant上に環境を作っておくと、さくさくとテストできます。
今回はansibleでdocker-ceのインストールに挑戦しました。

環境

  • vagrant centos72
  • ansible 2.4.0

ソースコード

作成するのは以下の3ファイル

  • Vagrantfile
  • hosts
  • playbook.yml

dockerはcentos6系にはインストールができないので、7系で。
Vagrantfileにあるcentos72は適当にcentos7のBOXを追加してください。

Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "centos72"
  config.vm.network "private_network", ip: "192.168.33.10"
end
hosts
[vagrants]
192.168.33.10 ansible_ssh_user=vagrant ansible_ssh_private_key_file=.vagrant/machines/default/virtualbox/private_key

ポイントはdockerグループの追加です。

playbook.yml
- hosts: vagrants
  user: vagrant
  become: yes
  tasks:
    - name: install yum-utils
      yum: name=yum-utils state=present

    - name: add docker repo
      shell: "yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo"
      args:
        chdir: "/etc/yum.repos.d"
        creates: docker-ce.repo

    - name: install docker-ce
      yum: name=docker-ce state=present

    - name: add group
      user: name=vagrant groups=docker append=yes
      tags: dockerhost
      become: True

    - name: restart docker
      systemd:
        name: docker.service
        state: restarted
        daemon_reload: yes
        enabled: yes

実行

$ vagrant up
$ ansible-playbook -i hosts playbook.yml

これで、vagrant上のcentosにdockerをインストールできます。

github サンプル

7
4
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
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?