Skip to content

Instantly share code, notes, and snippets.

@jovenbico
Last active January 22, 2019 11:24
Show Gist options
  • Save jovenbico/fb0ebe6b8ec42103422efd2c2885384d to your computer and use it in GitHub Desktop.
Save jovenbico/fb0ebe6b8ec42103422efd2c2885384d to your computer and use it in GitHub Desktop.
Vagrant ubuntu/ with ansible and docker

Vagrant ubuntu/ with ansible and docker

Usage

Start Vagrant provisioning

$ vagrant up --provision
$ vagrant ssh

Start docker node

$ docker-compose up -d

Create ansible inventory

$ nano inventory
cs-v-node1 ansible_ssh_user=root ansible_ssh_pass=Passw0rd ansible_host=172.16.238.10
cs-v-node2 ansible_ssh_user=root ansible_ssh_pass=Passw0rd ansible_host=172.16.238.20
cs-v-node3 ansible_ssh_user=root ansible_ssh_pass=Passw0rd ansible_host=172.16.238.30
$ nano ansible.cfg
[defaults]
host_key_checking = False

Test ansible inventory

$ ansible cs-v-node* -m ping -i inventory -vv

Enable ssh with password to Vagrant box

$ sudo nano /etc/ssh/sshd_config
PasswordAuthentication yes
$ sudo service ssh restart
version: "3"
services:
cs-v-node1:
container_name: cs-v-node1
image: jovenbico/ubuntu-ssh-enabled:v2
privileged: true
ports:
- "8080:80"
networks:
app_net:
ipv4_address: 172.16.238.10
cs-v-node2:
container_name: cs-v-node2
image: jovenbico/ubuntu-ssh-enabled:v2
privileged: true
networks:
app_net:
ipv4_address: 172.16.238.20
cs-v-node3:
container_name: cs-v-node3
image: jovenbico/ubuntu-ssh-enabled:v2
privileged: true
networks:
app_net:
ipv4_address: 172.16.238.30
networks:
app_net:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.16.238.0/24
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:Passw0rd' | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.box_check_update = false
config.vm.hostname = "ansible-server"
config.vm.network "private_network", ip: "192.168.33.20"
config.vm.provider "virtualbox" do |vbox|
vbox.name = "ubuntu_ansible_sshd"
vbox.memory = "4096"
vbox.cpus = 2
end
config.vm.provision "shell", inline: $install_ansible_script
config.vm.synced_folder "D:\\_My_Documents\\Workspace\\jalportal-projects\\jal-deployment\\ansible-configs", "/ansible-configs"
end
$install_ansible_script = <<-SCRIPT
echo '### Install Docker CE'
apt-get update && apt-get upgrade -y
apt-get -y install apt-transport-https ca-certificates curl gnupg2 software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get update && apt-get -y install docker-ce=18.06.1~ce~3-0~ubuntu
echo '### Adding vagrant user to docker group'
usermod -aG docker vagrant
echo '### Install Docker Compose'
curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
echo '### Pull Docker Image jovenbico/ubuntu-ssh-enabled'
docker pull jovenbico/ubuntu-ssh-enabled:v2
echo '### Install Ansible'
apt-get -y install python-pip && pip install 'ansible==2.7.6'
echo '### Install sshpass'
apt-get -y install sshpass
SCRIPT
@jovenbico
Copy link
Author

jovenbico commented Jan 21, 2019

TODO:

  • setup docker-compose
  • update image to have ping, telnet and curl command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment