Sie sind auf Seite 1von 7

3 $ vnqrnnt lnlt

edit vnqrnnttlle to add the boxname

2
3
vnqrnnt::contlq.run do |contlq|
contlq.vm.box = 'devserver'
end
2.
add a base image or box to quickly clone a virtual machine. this will create a folder .vagrant
with an ubuntu box
$ vnqrnnt box ndd devserver htt:]]tlles.vnqrnntu.com]reclse32.box
3.
then you are ready to go

2
3
4
$
6
7
8
9
0

2
3
4
$ vnqrnnt u
]detnult] 1mortlnq bnse box 'reclse32'...
]detnult] Mntchlnq MAc nddress tor HA1 networklnq...
]detnult] clenrlnq nny revlously set torwnrded orts...
]detnult] lorwnrdlnq orts...
]detnult] -- 22 =~ 2222 (ndnter )
]detnult] crentlnq shnred tolders metndntn...
]detnult] clenrlnq nny revlously set network lntertnces...
]detnult] 8ootlnq vM...
]detnult] wnltlnq tor vM to boot. 1hls cnn tnke n tew mlnutes.
]detnult] vM booted nnd rendy tor use!
]detnult] Mountlnq shnred tolders...
]detnult] -- v-root: ]vnqrnnt
]...]
4.
Wait for the command to hnish, then you will have a VM ready for you to connect. the VM can
be accessed via SSH:
$ vnqrnnt ssh

Vagrant allow you to use diherent Provisioners to easily setup your VM with everything it needs
to run your pro|ect :
Chef Solo
Chef Server
Puppet Standalone
Puppet Server
Shell
l do prefer Puppet for provisioning, because it's easy and it allow you to easily create a manifest
to control the package, hle or service with a few lines of code.
Here is the vnqrnnttlle i use, i needed to forward the port 8000 because i want to access the
webapp using my browser, i also increased the memory of the VM to 1CB, and made the pro|ect
folder accessible to the VM :

2
3
4
$
6
# -- mode: ruby --
# vl: set tt=ruby :
vnqrnnt::contlq.run do |lt|
lt.vm.box = 'lt-devserver'
Automate Your Dev Environment With Vagrant - Adnan... http://daker.me/2013/09/automate-your-dev-environment-...
2 of 7 11/14/2013 01:22 PM
7
8
9
0

2
3
4
$
6
7
8
9
20
2
lt.vm.box_url = 'htt:]]tlles.vnqrnntu.com]reclse32.box'
lt.vm.torwnrd_ort 8000, 8000
lt.vm.network :hostonly, '33.33.33.0'
lt.vm.customlze ]'modltyvm', :ld, '--memory', 024]
lt.ssh.mnx_trles = $0
lt.ssh.tlmeout = 300
lt.vm.shnre_tolder('v-root', ']home]vnqrnnt]lt', '.')
lt.vm.rovlslon :uet do |uet|
uet.mnnltests_nth = 'uet]mnnltests'
uet.mnnltest_tlle = 'vnqrnnt.'
end
end
here one of the classes i use on my dev environement :

2
3
4
$
6
7
8
9
0

2
3
4
$
6
7
8
9
20
2
22
23
24
2$
26
27
28
clnss lnlt {
qrou { 'uet':
ensure =~ 'resent',
}
# Let's udnte the system
exec { 'udnte-nt':
commnnd =~ 'sudo nt-qet udnte',
}
# Let's lnstnll the deendecles
ncknqe {
]'ython', 'ython-dev', 'llb]s-]query', 'llb]s-]query-ul', 'lso-codes', 'qettext', 'ython-l',
'bzr']:
ensure =~ lnstnlled,
requlre =~ Lxec]'udnte-nt'] # 1he system udnte needs to run tlrst
}
# Let's lnstnll the ro]ect deendecles trom l
exec { 'l-lnstnll-requlrements':
commnnd =~ 'sudo ]usr]bln]l lnstnll -r $k0J_01k]requlrements.txt',
trles =~ 2,
tlmeout =~ 600, # 1oo lonq, but thls cnn tnke nwhlle
requlre =~ ncknqe]'ython-l', 'ython-dev'], # 1he ncknqe deendecles needs to run tlrst
loqoutut =~ on_tnllure,
}
}
You need to specify one manifest hle in your Vagranhle, if you need to split it, you can use
something like this :

2
3
4
$
6
7
$ tree
.
'-- mnnltests
|-- clnsses
| |-- lnlt.
| '-- lt.
'-- vnqrnnt.
l use vnqrnnt. to dehne my pro|ect variables, and to make sure all the classes are executed in
the order i want :

2
3
4
lmort 'clnsses].'
$k0J_01k = ']home]vnqrnnt]lt'
Automate Your Dev Environment With Vagrant - Adnan... http://daker.me/2013/09/automate-your-dev-environment-...
3 of 7 11/14/2013 01:22 PM
$
6
7
8
9
0

2
3
4
$
6
7
Lxec {
nth =~ ']usr]locnl]bln:]usr]bln:]usr]sbln:]sbln:]bln',
}
clnss dev {
clnss {
lnlt: betore =~ clnss]lt],
lt:,
}
}
lnclude dev
1he lt class is only used to run some d]nnqo commands :

2
3
4
$
6
7
8
9
0

2
3
4
$
6
7
8
9
20
2
22
23
24
2$
26
27
clnss lt {
tlle { '$k0J_01k]loco_dlrectory]locnl_settlnqs.y':
ensure =~ tlle,
source =~ '$k0J_01k]loco_dlrectory]locnl_settlnqs.y.snmle',
relnce =~ tnlse,
}
exec {
'db_downlond':
cwd =~ '$k0J_01k]loco_dlrectory',
commnnd =~ ']usr]bln]wqet htt:]]eole.ubuntu.com]~dnker]lt]lt.db',
crentes =~ '$k0J_01k]loco_dlrectory]lt.db',
}
exec {
'mnnnqey_syncdb':
cwd =~ '$k0J_01k]loco_dlrectory',
commnnd =~ ']usr]bln]ython mnnnqe.y syncdb --nolnut',
}
exec {
'mnnnqey_mlqrntedb':
cwd =~ '$k0J_01k]loco_dlrectory',
commnnd =~ ']usr]bln]ython mnnnqe.y mlqrnte',
}
}
Now all i have to do is vnqrnnt u and let Vagrant do all his magic tricks :

2
3
4
$
6
7
8
9
0

2
3
4
$
6
7
8
9
20
2
22
$ vnqrnnt u
]detnult] 1mortlnq bnse box 'lt-devserver'...
]detnult] Mntchlnq MAc nddress tor HA1 networklnq...
]detnult] clenrlnq nny revlously set torwnrded orts...
]detnult] lorwnrdlnq orts...
]detnult] -- 22 =~ 2222 (ndnter )
]detnult] -- 8000 =~ 8000 (ndnter )
]detnult] crentlnq shnred tolders metndntn...
]detnult] clenrlnq nny revlously set network lntertnces...
]detnult] renrlnq network lntertnces bnsed on contlqurntlon...
]detnult] kunnlnq nny vM customlzntlons...
]detnult] 8ootlnq vM...
]detnult] wnltlnq tor vM to boot. 1hls cnn tnke n tew mlnutes.
]detnult] vM booted nnd rendy tor use!
]detnult] contlqurlnq nnd ennbllnq network lntertnces...
]detnult] Mountlnq shnred tolders...
]detnult] -- v-root: ]home]vnqrnnt]lt
]detnult] -- mnnltests: ]tm]vnqrnnt-uet]mnnltests
]detnult] kunnlnq rovlsloner: vnqrnnt::rovlsloners::uet...
]detnult] kunnlnq uet wlth ]tm]vnqrnnt-uet]mnnltests]vnqrnnt....
stdln: ls not n tty
wnrnlnq: could not retrleve tnct tqdn
Automate Your Dev Environment With Vagrant - Adnan... http://daker.me/2013/09/automate-your-dev-environment-...
4 of 7 11/14/2013 01:22 PM
Copyright 2013 Adnane Belmadiaf
1his work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License
Automate Your Dev Environment With Vagrant - Adnan... http://daker.me/2013/09/automate-your-dev-environment-...
7 of 7 11/14/2013 01:22 PM

Das könnte Ihnen auch gefallen