mirror of
https://codeberg.org/scottslowe/learning-tools.git
synced 2026-03-11 09:04:37 +00:00
Commit initial set of files for creating Swarm on Ubuntu with Ansible
Commit initial set of files to creating a Docker Swarm cluster (in Swarm mode) using Ubuntu and Ansible. Environment is currently not functional (Ansible/SSH won't correctly authenticate against the hosts). Signed-off-by: Scott Lowe <scott.lowe@scottlowe.org>
This commit is contained in:
parent
4846495848
commit
d5afc5e4c4
6 changed files with 205 additions and 0 deletions
74
docker/ubuntu-swarm-mode/Vagrantfile
vendored
Normal file
74
docker/ubuntu-swarm-mode/Vagrantfile
vendored
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
# Specify minimum Vagrant version and Vagrant API version
|
||||
Vagrant.require_version '>= 1.6.0'
|
||||
VAGRANTFILE_API_VERSION = '2'
|
||||
|
||||
# Require 'yaml' module
|
||||
require 'yaml'
|
||||
|
||||
# Read YAML file with VM details (box, CPU, RAM, IP addresses)
|
||||
# Edit machines.yml to change VM configuration details
|
||||
machines = YAML.load_file(File.join(File.dirname(__FILE__), 'machines.yml'))
|
||||
|
||||
# Create and configure the VMs
|
||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
|
||||
# Always use Vagrant's default insecure key
|
||||
config.ssh.insert_key = false
|
||||
|
||||
# Iterate through entries in YAML file to create VMs
|
||||
machines.each do |machine|
|
||||
|
||||
# Configure the VMs per details in machines.yml
|
||||
config.vm.define machine['name'] do |srv|
|
||||
|
||||
# Don't check for box updates
|
||||
srv.vm.box_check_update = false
|
||||
|
||||
# Specify the hostname of the VM
|
||||
srv.vm.hostname = machine['name']
|
||||
|
||||
# Specify the Vagrant box to use (use VMware box by default)
|
||||
srv.vm.box = machine['box']['vmw']
|
||||
|
||||
# Configure default synced folder (disable by default)
|
||||
if machine['sync_disabled'] != nil
|
||||
srv.vm.synced_folder '.', '/vagrant', disabled: machine['sync_disabled']
|
||||
else
|
||||
srv.vm.synced_folder '.', '/vagrant', disabled: true
|
||||
end #if machine['sync_disabled']
|
||||
|
||||
# Iterate through networks as per settings in machines.yml
|
||||
machine['nics'].each do |net|
|
||||
if net['ip_addr'] == 'dhcp'
|
||||
srv.vm.network net['type'], type: net['ip_addr']
|
||||
else
|
||||
srv.vm.network net['type'], ip: net['ip_addr']
|
||||
end # if net['ip_addr']
|
||||
end # machine['nics'].each
|
||||
|
||||
# Configure CPU & RAM per settings in machines.yml (Fusion)
|
||||
srv.vm.provider 'vmware_fusion' do |vmw|
|
||||
vmw.vmx['memsize'] = machine['ram']
|
||||
vmw.vmx['numvcpus'] = machine['vcpu']
|
||||
if machine['nested'] == true
|
||||
vmw.vmx['vhv.enable'] = 'TRUE'
|
||||
end #if machine['nested']
|
||||
end # srv.vm.provider 'vmware_fusion'
|
||||
|
||||
# Configure CPU & RAM per settings in machines.yml (VirtualBox)
|
||||
srv.vm.provider 'virtualbox' do |vb, override|
|
||||
vb.memory = machine['ram']
|
||||
vb.cpus = machine['vcpu']
|
||||
override.vm.box = machine['box']['vb']
|
||||
end # srv.vm.provider 'virtualbox'
|
||||
end # config.vm.define
|
||||
|
||||
# Run simple Ansible playbook
|
||||
config.vm.provision 'ansible' do |ansible|
|
||||
ansible.playbook = 'provision.yml'
|
||||
end # config.vm.provision
|
||||
end # machines.each
|
||||
end # Vagrant.configure
|
||||
8
docker/ubuntu-swarm-mode/ansible.cfg
Normal file
8
docker/ubuntu-swarm-mode/ansible.cfg
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[defaults]
|
||||
inventory = .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
|
||||
private_key_file = ~/.vagrant.d/insecure_private_key
|
||||
remote_user = vagrant
|
||||
host_key_checking = false
|
||||
|
||||
[ssh_connection]
|
||||
ssh_args = -o IdentityFile=/home/slowe/.vagrant.d/insecure_private_key -o PubKeyAuthentication=yes -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=~/.ansible/cp/ansible-ssh-%h-%p-%r
|
||||
59
docker/ubuntu-swarm-mode/create-swarm.yml
Normal file
59
docker/ubuntu-swarm-mode/create-swarm.yml
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
---
|
||||
- hosts: "all"
|
||||
become: "yes"
|
||||
remote_user: "vagrant"
|
||||
|
||||
tasks:
|
||||
- name: "Install Pip"
|
||||
package:
|
||||
name: "python-pip"
|
||||
state: "present"
|
||||
|
||||
- name: "Install some Python modules"
|
||||
pip:
|
||||
name: "{{ item }}"
|
||||
state: "present"
|
||||
with_items:
|
||||
- "urllib3"
|
||||
- "pyopenssl"
|
||||
- "ndg-httpsclient"
|
||||
- "pyasn1"
|
||||
|
||||
- name: "Install Docker APT Key"
|
||||
apt_key:
|
||||
url: "https://download.docker.com/linux/ubuntu/gpg"
|
||||
state: "present"
|
||||
|
||||
- name: "Add Docker repository"
|
||||
apt_repository:
|
||||
repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu trusty stable"
|
||||
state: "present"
|
||||
update_cache: "yes"
|
||||
|
||||
- name: "Install Docker CE"
|
||||
package:
|
||||
name: "docker-ce"
|
||||
state: "present"
|
||||
|
||||
- name: "Add user to Docker group"
|
||||
user:
|
||||
name: "{{ ansible_ssh_user }}"
|
||||
group: "docker"
|
||||
append: "yes"
|
||||
|
||||
- name: "Initialize Docker Swarm from manager"
|
||||
command: "docker swarm init --advertise-addr {{ ansible_default_ipv4.address }}"
|
||||
when: "ansible.hostname == manager"
|
||||
|
||||
- name: "Register Swarm join token"
|
||||
command: "docker swarm join-token -q worker"
|
||||
register: swarm_token
|
||||
when: "ansible.hostname == manager"
|
||||
|
||||
- name: "Establish Swarm join token as a host fact"
|
||||
set_fact: swarmtoken="{{ swarm_token.stdout }}"
|
||||
when: "ansible.hostname == manager"
|
||||
|
||||
- name: "Join worker nodes to Swarm cluster"
|
||||
command: "docker swarm join --advertise-addr {{ ansible_default_ipv4.address }} --token {{ hostvars[groups['tag_role_manager'][0]].swarmtoken }} {{ hostvars[groups['tag_role_manager'][0]].ansible_default_ipv4.address }}:2377"
|
||||
when: "ansible.hostname != manager"
|
||||
8
docker/ubuntu-swarm-mode/destroy-swarm.yml
Normal file
8
docker/ubuntu-swarm-mode/destroy-swarm.yml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
- hosts: "all"
|
||||
become: "yes"
|
||||
remote_user: "vagrant"
|
||||
|
||||
tasks:
|
||||
- name: "Leave Swarm cluster"
|
||||
command: "docker swarm leave --force"
|
||||
46
docker/ubuntu-swarm-mode/machines.yml
Normal file
46
docker/ubuntu-swarm-mode/machines.yml
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
---
|
||||
- box:
|
||||
vmw: "bento/ubuntu-14.04"
|
||||
vb: "ubuntu/trusty64"
|
||||
name: "manager"
|
||||
nics:
|
||||
- type: "private_network"
|
||||
ip_addr: "192.168.100.100"
|
||||
ram: "512"
|
||||
vcpu: "1"
|
||||
- box:
|
||||
vmw: "bento/ubuntu-14.04"
|
||||
vb: "ubuntu/trusty64"
|
||||
name: "worker-01"
|
||||
nics:
|
||||
- type: "private_network"
|
||||
ip_addr: "192.168.100.101"
|
||||
ram: "512"
|
||||
vcpu: "1"
|
||||
- box:
|
||||
vmw: "bento/ubuntu-14.04"
|
||||
vb: "ubuntu/trusty64"
|
||||
name: "worker-02"
|
||||
nics:
|
||||
- type: "private_network"
|
||||
ip_addr: "192.168.100.102"
|
||||
ram: "512"
|
||||
vcpu: "1"
|
||||
- box:
|
||||
vmw: "bento/ubuntu-14.04"
|
||||
vb: "ubuntu/trusty64"
|
||||
name: "worker-03"
|
||||
nics:
|
||||
- type: "private_network"
|
||||
ip_addr: "192.168.100.103"
|
||||
ram: "512"
|
||||
vcpu: "1"
|
||||
- box:
|
||||
vmw: "bento/ubuntu-14.04"
|
||||
vb: "ubuntu/trusty64"
|
||||
name: "worker-04"
|
||||
nics:
|
||||
- type: "private_network"
|
||||
ip_addr: "192.168.100.104"
|
||||
ram: "512"
|
||||
vcpu: "1"
|
||||
10
docker/ubuntu-swarm-mode/provision.yml
Normal file
10
docker/ubuntu-swarm-mode/provision.yml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
- hosts: "all"
|
||||
become: "yes"
|
||||
remote_user: "vagrant"
|
||||
|
||||
tasks:
|
||||
- name: "Install Pip"
|
||||
package:
|
||||
name: "python-pip"
|
||||
state: "present"
|
||||
Loading…
Reference in a new issue