Integrate changes from ubuntu-swarm-mode environment

Integrate changes to create-swarm.yml, destroy-swarm.yml, machines.yml, and provision.yml based on learnings from the ubuntu-swarm-mode environment

Signed-off-by: Scott Lowe <scott.lowe@scottlowe.org>
This commit is contained in:
Scott Lowe 2017-09-14 07:35:48 -06:00
parent 1a47f0fc21
commit 12215bbf7e
No known key found for this signature in database
GPG key ID: 949F43F6E6C11780
4 changed files with 83 additions and 19 deletions

View file

@ -4,19 +4,83 @@
remote_user: "vagrant"
tasks:
- name: "Install Pip"
apt:
name: "python-pip"
state: "present"
update_cache: "yes"
tags:
- manager
- worker
- name: "Install some Python modules"
pip:
name: "{{ item }}"
state: "present"
with_items:
- "urllib3"
- "pyopenssl"
- "ndg-httpsclient"
- "pyasn1"
tags:
- manager
- worker
- name: "Install Docker APT Key"
apt_key:
url: "https://download.docker.com/linux/ubuntu/gpg"
state: "present"
tags:
- manager
- worker
- name: "Add Docker repository"
apt_repository:
repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu trusty stable"
state: "present"
update_cache: "yes"
tags:
- manager
- worker
- name: "Install Docker CE"
package:
name: "docker-ce"
state: "present"
tags:
- manager
- worker
- name: "Add user to Docker group"
user:
name: "{{ ansible_ssh_user }}"
group: "docker"
append: "yes"
tags:
- manager
- worker
- name: "Initialize Docker Swarm from manager"
command: "docker swarm init --advertise-addr {{ ansible_default_ipv4.address }}"
when: ansible_hostname == "manager"
command: "docker swarm init --advertise-addr {{ ansible_eth1.ipv4.address }}"
when: ansible_hostname == 'manager'
tags:
- manager
- name: "Register Swarm join token"
command: "docker swarm join-token -q worker"
register: swarm_token
when: ansible_hostname == "manager"
when: ansible_hostname == 'manager'
tags:
- manager
- name: "Establish Swarm join token as a host fact"
set_fact: swarmtoken="{{ swarm_token.stdout }}"
when: ansible_hostname == "manager"
when: ansible_hostname == 'manager'
tags:
- manager
- name: "Join worker nodes to Swarm cluster"
command: "docker swarm join --advertise-addr {{ ansible_default_ipv4.address }} --token {{ swarmtoken }} {{ hostvars[groups['tag_role_manager'][0]].ansible_default_ipv4.address }}:2377"
when: ansible_hostname != "manager"
command: "docker swarm join --advertise-addr {{ ansible_eth1.ipv4.address }} --token {{ hostvars['manager'].swarmtoken }} {{ hostvars['manager']['ansible_eth1']['ipv4']['address'] }}:2377"
when: ansible_hostname != 'manager'
tags:
- worker

View file

@ -1,7 +1,7 @@
---
- hosts: "us-west-2"
- hosts: "all"
become: "yes"
remote_user: "ubuntu"
remote_user: "vagrant"
tasks:
- name: "Leave Swarm cluster"

View file

@ -1,7 +1,7 @@
---
- box:
vmw: "centos/atomic-host"
vb: "fedora/26-atomic-host"
vmw: "bento/ubuntu-14.04"
vb: "bento/ubuntu-14.04"
name: "manager"
nics:
- type: "private_network"
@ -9,8 +9,8 @@
ram: "512"
vcpu: "1"
- box:
vmw: "centos/atomic-host"
vb: "fedora/26-atomic-host"
vmw: "bento/ubuntu-14.04"
vb: "bento/ubuntu-14.04"
name: "worker-01"
nics:
- type: "private_network"
@ -18,8 +18,8 @@
ram: "512"
vcpu: "1"
- box:
vmw: "centos/atomic-host"
vb: "fedora/26-atomic-host"
vmw: "bento/ubuntu-14.04"
vb: "bento/ubuntu-14.04"
name: "worker-02"
nics:
- type: "private_network"
@ -27,8 +27,8 @@
ram: "512"
vcpu: "1"
- box:
vmw: "centos/atomic-host"
vb: "fedora/26-atomic-host"
vmw: "bento/ubuntu-14.04"
vb: "bento/ubuntu-14.04"
name: "worker-03"
nics:
- type: "private_network"
@ -36,8 +36,8 @@
ram: "512"
vcpu: "1"
- box:
vmw: "centos/atomic-host"
vb: "fedora/26-atomic-host"
vmw: "bento/ubuntu-14.04"
vb: "bento/ubuntu-14.04"
name: "worker-04"
nics:
- type: "private_network"

View file

@ -1,7 +1,7 @@
---
- hosts: "all"
remote_user: "vagrant"
become: "yes"
remote_user: "vagrant"
tasks:
- name: Verify Ansible connectivity