Skip to content

Instantly share code, notes, and snippets.

@nutti
Last active August 29, 2015 14:19
Show Gist options
  • Save nutti/9d8ab00da9485689fa36 to your computer and use it in GitHub Desktop.
Save nutti/9d8ab00da9485689fa36 to your computer and use it in GitHub Desktop.
[Ansible] Vagrantで構築した仮想マシンに対してAnsibleを試した時のメモ ref: http://qiita.com/nutti/items/c57c4031c83680f17645
$ yum install https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2_x86_64.rpm
$ yum install https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2_x86_64.rpm
$ vagrant version
Installed Version: 1.7.2
$ vagrant version
Installed Version: 1.7.2
$ yum install ansible
$ yum install ansible
$ cd ~/ansible
$ touch hosts
$ cd ~/ansible
$ touch hosts
[ansible-nodes]
192.168.100.10 ansible_ssh_user=vagrant ansible_ssh_private_key_file=.vagrant/machines/node1/virtualbox/private_key
192.168.100.11 ansible_ssh_user=vagrant ansible_ssh_private_key_file=.vagrant/machines/node2/virtualbox/private_key
192.168.100.12 ansible_ssh_user=vagrant ansible_ssh_private_key_file=.vagrant/machines/node3/virtualbox/private_key
[ansible-nodes]
192.168.100.10 ansible_ssh_user=vagrant ansible_ssh_private_key_file=.vagrant/machines/node1/virtualbox/private_key
192.168.100.11 ansible_ssh_user=vagrant ansible_ssh_private_key_file=.vagrant/machines/node2/virtualbox/private_key
192.168.100.12 ansible_ssh_user=vagrant ansible_ssh_private_key_file=.vagrant/machines/node3/virtualbox/private_key
$ cp ~/.ssh/config ~/.ssh/config.orig
$ vagrant ssh-config > ~/.ssh/config
$ cp ~/.ssh/config ~/.ssh/config.orig
$ vagrant ssh-config > ~/.ssh/config
$ ansible -i hosts ansible-nodes -m ping
192.168.100.10 | success >> {
"changed": false,
"ping": "pong"
}
192.168.100.11 | success >> {
"changed": false,
"ping": "pong"
}
192.168.100.12 | success >> {
"changed": false,
"ping": "pong"
}
$ ansible -i hosts ansible-nodes -m ping
192.168.100.10 | success >> {
"changed": false,
"ping": "pong"
}
192.168.100.11 | success >> {
"changed": false,
"ping": "pong"
}
192.168.100.12 | success >> {
"changed": false,
"ping": "pong"
}
$ ssh node1
$ which gcc
/usr/bin/which: no gcc in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/vagrant/bin)
$ which gdb
/usr/bin/which: no gdb in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/vagrant/bin)
$ ssh node2
$ which gcc
/usr/bin/which: no gcc in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/vagrant/bin)
$ which gdb
/usr/bin/which: no gdb in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/vagrant/bin)
$ ssh node3
$ which gcc
/usr/bin/which: no gcc in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/vagrant/bin)
$ which gdb
/usr/bin/which: no gdb in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/vagrant/bin)
$ ssh node1
$ which gcc
/usr/bin/which: no gcc in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/vagrant/bin)
$ which gdb
/usr/bin/which: no gdb in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/vagrant/bin)
$ ssh node2
$ which gcc
/usr/bin/which: no gcc in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/vagrant/bin)
$ which gdb
/usr/bin/which: no gdb in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/vagrant/bin)
$ ssh node3
$ which gcc
/usr/bin/which: no gcc in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/vagrant/bin)
$ which gdb
/usr/bin/which: no gdb in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/vagrant/bin)
- hosts: ansible-nodes
sudo: yes
tasks:
- name: install gcc
yum: name=gcc state=installed
- name: install gdb
yum: name=gdb state=installed
---
- hosts: ansible-nodes
sudo: yes
tasks:
- name: install gcc
yum: name=gcc state=installed
- name: install gdb
yum: name=gdb state=installed
$ ansible-playbook -i hosts playbook.yml
PLAY [ansible-nodes] **********************************************************
GATHERING FACTS ***************************************************************
ok: [192.168.100.12]
ok: [192.168.100.11]
ok: [192.168.100.10]
TASK: [install gcc] ***********************************************************
changed: [192.168.100.11]
changed: [192.168.100.10]
changed: [192.168.100.12]
TASK: [install gdb] ***********************************************************
changed: [192.168.100.10]
changed: [192.168.100.11]
changed: [192.168.100.12]
PLAY RECAP ********************************************************************
192.168.100.10 : ok=3 changed=2 unreachable=0 failed=0
192.168.100.11 : ok=3 changed=2 unreachable=0 failed=0
192.168.100.12 : ok=3 changed=2 unreachable=0 failed=0
$ ansible-playbook -i hosts playbook.yml
PLAY [ansible-nodes] **********************************************************
GATHERING FACTS ***************************************************************
ok: [192.168.100.12]
ok: [192.168.100.11]
ok: [192.168.100.10]
TASK: [install gcc] ***********************************************************
changed: [192.168.100.11]
changed: [192.168.100.10]
changed: [192.168.100.12]
TASK: [install gdb] ***********************************************************
changed: [192.168.100.10]
changed: [192.168.100.11]
changed: [192.168.100.12]
PLAY RECAP ********************************************************************
192.168.100.10 : ok=3 changed=2 unreachable=0 failed=0
192.168.100.11 : ok=3 changed=2 unreachable=0 failed=0
192.168.100.12 : ok=3 changed=2 unreachable=0 failed=0
$ ssh node1
$ which gcc
/usr/bin/gcc
$ which gdb
/usr/bin/gdb
$ ssh node2
$ which gcc
/usr/bin/gcc
$ which gdb
/usr/bin/gdb
$ ssh node3
$ which gcc
/usr/bin/gcc
$ which gdb
/usr/bin/gdb
$ ssh node1
$ which gcc
/usr/bin/gcc
$ which gdb
/usr/bin/gdb
$ ssh node2
$ which gcc
/usr/bin/gcc
$ which gdb
/usr/bin/gdb
$ ssh node3
$ which gcc
/usr/bin/gcc
$ which gdb
/usr/bin/gdb
$ vagrant halt
$ vagrant halt
$ cd ~/
$ mkdir ansible
$ cd ansible
$ cd ~/
$ mkdir ansible
$ cd ansible
$ vagrant destroy
$ vagrant destroy
$ vagrant init [名称] [box]
$ vagrant init [名称] [box]
$ vagrant init centos6.5_ansible http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box
$ vagrant init centos6.5_ansible http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box
$ cp Vagrantfile Vagrantfile.orig
$ diff Vagrantfile
$ cp Vagrantfile Vagrantfile.orig
$ diff Vagrantfile
15c15,29
< config.vm.box = "centos6.5_ansible"
---
> config.vm.define :node1 do |node|
> node.vm.box = "centos6.5_ansible"
> node.vm.network :private_network, ip: "192.168.100.10"
> end
>
> config.vm.define :node2 do |node|
> node.vm.box = "centos6.5_ansible"
> node.vm.network :private_network, ip: "192.168.100.11"
> end
>
> config.vm.define :node3 do |node|
> node.vm.box = "centos6.5_ansible"
> node.vm.network :private_network, ip: "192.168.100.12"
> end
>
$ vagrant up
$ vagrant up
$ vagrant status
Current machine states:
node1 running (virtualbox)
node2 running (virtualbox)
node3 running (virtualbox)
$ vagrant status
Current machine states:
node1 running (virtualbox)
node2 running (virtualbox)
node3 running (virtualbox)
$ vagrant ssh node1
(vagrantで作成した仮想マシン)
$ vagrant ssh node1
(vagrantで作成した仮想マシン)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment