-
-
Save JEDIBC/2b6eafd3775e62fa80f2 to your computer and use it in GitHub Desktop.
Vagrant with Docker provider and Ansible provisioning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Vagrantfile | |
``` | |
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
VAGRANTFILE_API_VERSION = "2" | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
config.vm.provider "docker" do |d| | |
d.build_dir = "./provisioning" | |
d.has_ssh = true | |
d.name = "vm-docker" | |
end | |
config.ssh.forward_agent = true | |
config.vm.synced_folder ".", "/vagrant" | |
config.vm.provision "ansible" do |ansible| | |
ansible.playbook = "provisioning/playbook.yml" | |
ansible.limit = 'all' | |
end | |
end | |
``` | |
Don't forget to run vagrant specifying the docker provider : | |
``` | |
vagrant up --provider=docker | |
``` | |
# Dockerfile | |
Basically you take a bare distro, add vagrant user and public key, and install openssh and python | |
``` | |
FROM debian:wheezy | |
MAINTAINER Bruno CHALOPIN "bruno@chalopin.fr" | |
ENV DEBIAN_FRONTEND noninteractive | |
RUN apt-get update && apt-get install -y ssh && apt-get clean | |
RUN mkdir /var/run/sshd | |
RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config | |
RUN sed -ri 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config | |
# Create and configure vagrant user | |
RUN useradd --create-home -s /bin/bash vagrant | |
# Configure SSH access | |
RUN mkdir -p /home/vagrant/.ssh | |
RUN echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" > /home/vagrant/.ssh/authorized_keys | |
RUN chown -R vagrant: /home/vagrant/.ssh | |
RUN echo -n 'vagrant:vagrant' | chpasswd | |
RUN touch /home/vagrant/.hushlogin | |
# Enable passwordless sudo for vagrant | |
RUN apt-get update && apt-get install -y sudo && apt-get clean | |
RUN mkdir -p /etc/sudoers.d && echo "vagrant ALL= NOPASSWD: ALL" > /etc/sudoers.d/vagrant && chmod 0440 /etc/sudoers.d/vagrant | |
# Enable python for ansible | |
RUN apt-get install -y python && apt-get clean | |
CMD ["/usr/sbin/sshd", "-D", "-e"] | |
EXPOSE 22 | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment