Last active
March 6, 2018 20:34
-
-
Save nicknezis/fd5845251a8805729cd05bfca5680a15 to your computer and use it in GitHub Desktop.
Vagrant Docker Ansible combo (centos7 with SSH)
This file contains hidden or 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
# Docker image to use with Vagrant | |
# Aims to be as similar to normal Vagrant usage as possible | |
# Adds Puppet, SSH daemon | |
FROM centos:centos7 | |
MAINTAINER Sam Bashton <[email protected]> | |
# Replace fake systemd with real systemd | |
# Lifted from http://jperrin.github.io/centos/2014/09/25/centos-docker-and-systemd/ | |
RUN yum -y swap -- remove fakesystemd -- install systemd systemd-libs initscripts | |
RUN yum -y update; yum clean all; \ | |
(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \ | |
rm -f /lib/systemd/system/multi-user.target.wants/*;\ | |
rm -f /etc/systemd/system/*.wants/*;\ | |
rm -f /lib/systemd/system/local-fs.target.wants/*; \ | |
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \ | |
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \ | |
rm -f /lib/systemd/system/basic.target.wants/*;\ | |
rm -f /lib/systemd/system/anaconda.target.wants/*; | |
VOLUME [ "/sys/fs/cgroup" ] | |
RUN yum -y install openssh-server openssh-clients | |
RUN yum -y install http://yum.puppetlabs.com/puppetlabs-release-pc1-el-7.noarch.rpm | |
RUN yum -y install puppet-agent hostname ansible | |
# Add vagrant user and key | |
RUN yum -y install sudo | |
RUN useradd --create-home -s /bin/bash vagrant | |
RUN echo -n 'vagrant:vagrant' | chpasswd | |
RUN echo 'vagrant ALL = NOPASSWD: ALL' > /etc/sudoers.d/vagrant | |
RUN chmod 440 /etc/sudoers.d/vagrant | |
RUN mkdir -p /home/vagrant/.ssh | |
RUN chmod 700 /home/vagrant/.ssh | |
RUN echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" > /home/vagrant/.ssh/authorized_keys | |
RUN chmod 600 /home/vagrant/.ssh/authorized_keys | |
RUN chown -R vagrant:vagrant /home/vagrant/.ssh | |
RUN sed -i -e 's/Defaults.*requiretty/#&/' /etc/sudoers | |
RUN sed -i -e 's/\(UsePAM \)yes/\1 no/' /etc/ssh/sshd_config | |
RUN systemctl enable sshd.service | |
CMD ["/usr/sbin/init"] |
This file contains hidden or 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
--- | |
- hosts: default | |
become: true | |
tasks: | |
- name: install mesosphere repo | |
yum: | |
pkg: http://repos.mesosphere.com/el/7/noarch/RPMS/mesosphere-el-repo-7-1.noarch.rpm | |
state: latest | |
- name: install Mesos and Marathon software | |
yum: pkg={{item}} state=installed | |
with_items: | |
- mesos | |
- marathon | |
- name: install Zookeeper | |
yum: pkg={{item}} state=installed | |
with_items: | |
- mesosphere-zookeeper | |
- name: add Docker repo | |
yum_repository: | |
name: dockerrepo | |
description: EPEL YUM repo | |
baseurl: https://yum.dockerproject.org/repo/main/centos/7/ | |
gpgcheck: yes | |
gpgkey: https://yum.dockerproject.org/gpg | |
- name: install Docker Engine | |
yum: pkg={{item}} state=installed | |
with_items: | |
- docker-engine |
This file contains hidden or 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
Vagrant.configure("2") do |config| | |
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker' | |
config.vm.provider "docker" do |d, override| | |
d.image = "bashtoni/centos7-vagrant:puppet4" | |
# d.build_dir = '.' | |
d.has_ssh = true | |
d.force_host_vm = false | |
override.ssh.host = '127.0.0.1' | |
port = `head -n1 .vagrant/machines/default/docker/id | xargs docker inspect | grep -n3 '22/tcp' | grep 'HostPort' | head -n1 | cut -d '"' -f 4`.chop | |
override.ssh.port = port.to_s.empty? ? 2222 : port | |
d.create_args = [ "--privileged", "-v", "/sys/fs/cgroup:/sys/fs/cgroup:ro" ] | |
end | |
# | |
# Run Ansible from the Vagrant Host | |
# | |
config.vm.provision "ansible" do |ansible| | |
ansible.playbook = "playbook.yml" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment