- Vagrant provides easy to configure, reproducible, and portable work environments.
- Drafting and testing ansible scripts
# apt-get install vagrant
- This command will also pull virtualbox
- let's use a debian image
- Go to https://atlas.hashicorp.com/boxes/search
- https://atlas.hashicorp.com/debian/boxes/jessie64
- Box name is debian/jessie64
$ vagrant box add debian/jessie64
- Add file named Vagrantfile with the following content
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure("2") do |config|
config.vm.box = "debian/jessie64"
end
- From the directory where Vagrant file is located
- Bring up the box:
$ vagrant up
$ vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /home/alex/git/gtalug/2016-10-11-ansible/2-testing/01-base/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
$ vagrant ssh
[defaults]
hostfile = hosts
remote_user = vagrant
private_key_file = .vagrant/machines/default/virtualbox/private_key
host_key_checking = False
[test]
testserver ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222
$ ansible test -m ping
testserver | SUCCESS => {
"changed": false,
"ping": "pong"
}
$ ansible-playbook -vvv base-packages.yaml
- This works however virtualbox is not a preferred hypervisor.
- It is not possible to run more than one hypervisor at a time.
# apt-get install vagrant-libvirt vagrant-mutate
- vagrant-libvirt -- libvirt available in stretch and newer
- vagrant-mutate -- convert original images to libvirt
$ vagrant plugin install vagrant-libvirt vagrant-mutate
Install libvirt version of the machine
# apt-get install vagrant-libvirt
$ vagrant box add debian/jessie64 --provider=libvirt
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure("2") do |config|
config.vm.provider :libvirt do |libvirt|
libvirt.uri = 'qemu+unix:///system'
libvirt.host = 'localhost'
libvirt.username = 'alex'
libvirt.connect_via_ssh = true
end
config.vm.define :libvirt_vm do |machine|
machine.vm.box = "debian/jessie64"
end
end
$vagrant up --provider=libvirt
$ vagrant ssh-config
Host libvirt_vm
HostName 192.168.121.237
User vagrant
Port 22
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /home/alex/git/gtalug/2016-10-11-ansible/2-testing/02-vagrant-libvirt/.vagrant/machines/libvirt_vm/libvirt/private_key
IdentitiesOnly yes
LogLevel FATAL
ProxyCommand ssh 'localhost' -l 'alex' -i '/home/alex/.ssh/id_rsa' nc %h %p
- Set a new path to private_key_file
private_key_file = .vagrant/machines/libvirt_vm/libvirt/private_key
vagrant_libvirt ansible_ssh_host=192.168.121.237 ansible_ssh_port=22
$ ansible test -m ping
testserver | SUCCESS => {
"changed": false,
"ping": "pong"
}
- Install debian system answering all the install questions
- Install debian-installer package on the system
- Extract the answers
# debconf-get-selections --installer > ${HOME}/preseed.cfg
# debconf-get-selections >> ${HOME}/preseed.cfg
- Ugly shell script in *gen_iso.sh
- Creates iso with preseed file based on debian-8.6.0-amd64-CD-1.iso
- See the video.
- First run copy ssh pubkey and some other things on a new system
$ ansible-playbook --ask-pass --ask-become-pass --ssh_port=2222 -i<hostname>, -vvv base_packages.yaml
- Backup command if script fails and you need to debug it
$ ansible-playbook -i<hostname>, -vvv base_packages.yaml
- http://stackoverflow.com/questions/18195142/safely-limiting-ansible-playbooks-to-a-single-machine
- http://stackoverflow.com/questions/17188147/how-to-run-ansible-without-specifying-the-inventory-but-the-host-directly
- using preseeding -- https://www.debian.org/releases/jessie/i386/apbs02.html.en
- edit iso -- https://wiki.debian.org/DebianInstaller/Preseed/EditIso
- Really fragile!