Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC flocker (not meant to be merged) #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.retry
.vagrant
.DS_Store
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,36 @@ At this stage of the project I just want to have a couple of services communicat
## Monitoring

Please see the [Changelog Roadmap](https://github.com/jamesdmorgan/vagrant-ansible-docker-swarm/blob/master/CHANGELOG.md#roadmap) for plans regarding monitoring of both the containers and the system in general.

## Flocker

install focker-ca

```
####flocker-ca
sudo python -m ensurepip
sudo pip install virtualenv
virtualenv --python=/usr/bin/python2.7 flocker-client
source flocker-client/bin/activate
pip install --upgrade pip
pip install https://clusterhq-archive.s3.amazonaws.com/python/Flocker-1.15.0-py2-none-any.whl
source flocker-client/bin/activate
flocker-ca --version
#####
```


```
cd ansible
export PYTHONUNBUFFERED=1
ansible-playbook --connection=ssh swarm.yml -vv
ansible-playbook --connection=ssh apps.yml -vv
###flocker env
source ../flocker-client/bin/activate
ansible-playbook --connection=ssh flocker.yml -vv
###
ansible-playbook --connection=ssh monitoring.yml -vv --tags "influxdb"
```

influxdb can start in any hosts, the config file will be attached to that host using flocker

130 changes: 68 additions & 62 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@
VAGRANTFILE_API_VERSION = "2"
MANAGERS = 3
WORKERS = 3
ANSIBLE_GROUPS = {
"managers" => ["manager[1:#{MANAGERS}]"],
"workers" => ["worker[1:#{WORKERS}]"],
"elk" => ["manager[2:2]"],
"influxdb" => ["manager[3:3]"],
"all_groups:children" => [
"managers",
"workers",
"elk",
"influxdb"]
}
# ANSIBLE_GROUPS = {
# "managers" => ["manager[1:#{MANAGERS}]"],
# "workers" => ["worker[1:#{WORKERS}]"],
# "elk" => ["manager[2:2]"],
# "influxdb" => ["manager[3:3]"],
# "flocker_control_service" => ["manager[1:1]"],
# "flocker_agents" => ["manager[1:#{MANAGERS}]", "worker[1:#{WORKERS}]"],
# "all_groups:children" => [
# "managers",
# "workers",
# "elk",
# "influxdb",
# "flocker_control_service",
# "flocker_agents"]
# }

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

Expand Down Expand Up @@ -60,57 +64,59 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
v.cpus = 2
end

# Only execute once the Ansible provisioner,
# when all the workers are up and ready.
if worker_id == WORKERS

# Install any ansible galaxy roles
worker.vm.provision "shell", type: "host_shell" do |sh|
sh.inline = "cd ansible && ansible-galaxy install -r requirements.yml -p roles --ignore-errors"
end

worker.vm.provision "swarm", type: "ansible" do |ansible|
ansible.limit = "all"
ansible.playbook = "ansible/swarm.yml"
ansible.verbose = "vv"
ansible.groups = ANSIBLE_GROUPS
end

# Addition provisioners are only called if --provision-with is passed
if ARGV.include? '--provision-with'
worker.vm.provision "consul", type: "ansible" do |ansible|
ansible.limit = "all"
ansible.playbook = "ansible/consul.yml"
ansible.verbose = "vv"
ansible.groups = ANSIBLE_GROUPS
end

worker.vm.provision "logging", type: "ansible" do |ansible|
ansible.limit = "all"
ansible.playbook = "ansible/logging.yml"
ansible.verbose = "vv"
ansible.sudo = true
ansible.groups = ANSIBLE_GROUPS
end

worker.vm.provision "monitoring", type: "ansible" do |ansible|
ansible.limit = "all"
ansible.playbook = "ansible/monitoring.yml"
ansible.verbose = "vv"
ansible.sudo = true
ansible.groups = ANSIBLE_GROUPS
end

worker.vm.provision "apps", type: "ansible" do |ansible|

# Only need to run against one of the managers since using swarm
ansible.limit = "managers*"
ansible.playbook = "ansible/apps.yml"
ansible.verbose = "vv"
ansible.groups = ANSIBLE_GROUPS
end
end
end

# # Only execute once the Ansible provisioner,
# # when all the workers are up and ready.
# if worker_id == WORKERS

# # Install any ansible galaxy roles
# worker.vm.provision "shell", type: "host_shell" do |sh|
# sh.inline = "cd ansible && ansible-galaxy install -r requirements.yml --ignore-errors"
# end

# #TODO provision should be done via ansible commands not in Vagrantfile
# worker.vm.provision "swarm", type: "ansible" do |ansible|
# ansible.limit = "all"
# ansible.playbook = "ansible/swarm.yml"
# ansible.verbose = "vv"
# ansible.groups = ANSIBLE_GROUPS
# end

# # Addition provisioners are only called if --provision-with is passed
# if ARGV.include? '--provision-with'
# worker.vm.provision "consul", type: "ansible" do |ansible|
# ansible.limit = "all"
# ansible.playbook = "ansible/consul.yml"
# ansible.verbose = "vv"
# ansible.groups = ANSIBLE_GROUPS
# end

# worker.vm.provision "logging", type: "ansible" do |ansible|
# ansible.limit = "all"
# ansible.playbook = "ansible/logging.yml"
# ansible.verbose = "vv"
# ansible.sudo = true
# ansible.groups = ANSIBLE_GROUPS
# end

# worker.vm.provision "monitoring", type: "ansible" do |ansible|
# ansible.limit = "all"
# ansible.playbook = "ansible/monitoring.yml"
# ansible.verbose = "vv"
# ansible.sudo = true
# ansible.groups = ANSIBLE_GROUPS
# end

# worker.vm.provision "apps", type: "ansible" do |ansible|

# # Only need to run against one of the managers since using swarm
# ansible.limit = "managers*"
# ansible.playbook = "ansible/apps.yml"
# ansible.verbose = "vv"
# ansible.groups = ANSIBLE_GROUPS
# end
# end
# end
end
end
end
11 changes: 11 additions & 0 deletions ansible/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[defaults]
hostfile = hosts
force_color = 1
host_key_checking = False
inventory = development
timeout = 30
roles_path = library:roles

[ssh_connection_type]
ssh_args = -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s

35 changes: 35 additions & 0 deletions ansible/development
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Vagrant

manager1 ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222 ansible_ssh_user='vagrant' ansible_ssh_private_key_file='/Users/pierrecaserta/.vagrant.d/insecure_private_key'
manager2 ansible_ssh_host=127.0.0.1 ansible_ssh_port=2200 ansible_ssh_user='vagrant' ansible_ssh_private_key_file='/Users/pierrecaserta/.vagrant.d/insecure_private_key'
manager3 ansible_ssh_host=127.0.0.1 ansible_ssh_port=2201 ansible_ssh_user='vagrant' ansible_ssh_private_key_file='/Users/pierrecaserta/.vagrant.d/insecure_private_key'
worker1 ansible_ssh_host=127.0.0.1 ansible_ssh_port=2202 ansible_ssh_user='vagrant' ansible_ssh_private_key_file='/Users/pierrecaserta/.vagrant.d/insecure_private_key'
worker2 ansible_ssh_host=127.0.0.1 ansible_ssh_port=2203 ansible_ssh_user='vagrant' ansible_ssh_private_key_file='/Users/pierrecaserta/.vagrant.d/insecure_private_key'
worker3 ansible_ssh_host=127.0.0.1 ansible_ssh_port=2204 ansible_ssh_user='vagrant' ansible_ssh_private_key_file='/Users/pierrecaserta/.vagrant.d/insecure_private_key'

[managers]
manager[1:3]

[workers]
worker[1:3]

[elk]
manager[2:2]

[influxdb]
manager[3:3]

[flocker_control_service]
manager[1:1]

[flocker_agents]
manager[1:3]
worker[1:3]

[all_groups:children]
managers
workers
elk
influxdb
flocker_control_service
flocker_agents
20 changes: 20 additions & 0 deletions ansible/flocker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
- hosts: all
vars:
flocker_control_service_groupname: flocker_control_service
flocker_agents_groupname: flocker_agents
flocker_cluster_name: my_flocker_cluster
flocker_install_docker_plugin: true
flocker_api_cert_name: plugin
flocker_local_tempdir: /tmp/{{ flocker_cluster_name }}
flocker_agent_yml_path: /Users/others/working/aa_working/ansible/vagrant-ansible-docker-swarm/ansible/roles/loopback/files/agent.yml
roles:
- { role: ClusterHQ.flocker, tags: [flocker] }

- hosts: managers[1:]
become: yes
become_user: root
tasks:
- name: "Restart flocker-docker-plugin.service"
shell: >
systemctl restart flocker-docker-plugin
24 changes: 24 additions & 0 deletions ansible/library/ClusterHQ.flocker/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
language: python
python: "2.7"
sudo: required
dist: trusty

before_install:
# Make sure everything's up to date.
- sudo apt-get update -qq

install:
# Install Ansible.
- pip install ansible
# Install flocker
- sudo apt-get -y install gcc libffi-dev libssl-dev python2.7 python2.7-dev python-virtualenv
- sudo pip install --find-links=https://s3.amazonaws.com/clusterhq-archive/python/index.html Flocker
# Add ansible.cfg to pick up roles path.
- "{ echo '[defaults]'; echo 'roles_path = ../'; } >> ansible.cfg"

script:
# Check the role/playbook's syntax.
- "ansible-playbook -i tests/inventory tests/test.yml --syntax-check"
# Make sure we can run all the plays
- "ansible-playbook -i tests/inventory tests/test.yml --connection=local --extra-vars 'flocker_agent_yml_path=tests/agent.yml'"
21 changes: 21 additions & 0 deletions ansible/library/ClusterHQ.flocker/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 ClusterHQ

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
69 changes: 69 additions & 0 deletions ansible/library/ClusterHQ.flocker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Ansible Role: Flocker Installer

[![Build Status](https://travis-ci.org/ClusterHQ/ansible-role-flocker.svg?branch=master)](https://travis-ci.org/ClusterHQ/ansible-role-flocker.svg?branch=master)

## Requirements

* Docker must be installed on all Flocker agent nodes.
* This role requires you install the Flocker Client on the machine running the ansible playbook. Certificates are generated on the local machine (in `flocker_local_tempdir`) using flocker-ca and then distributed to the nodes. For more information see [Installing the Flocker Client](https://docs.clusterhq.com/en/latest/flocker-standalone/install-client.html).
* The user must supply the path to a local agent.yml flocker file.

## Role Variables

flocker_control_service_groupname: flocker_control_service

The name of an ansible host group that contains one host: the node hosting the flocker control service. The default value for this group name is flocker_control_serivce. If the host group is called something else, change this variable to match the host group name you've chosen.

flocker_agents_groupname: flocker_agents

Similar to flocker_control_service_groupname but represents the groupname of the Flocker agent nodes.

flocker_agent_yml_path: ""

The absolute path to an agent.yml file on the local ansible machine. For more information on creating agent.yml refer to Configuring the Nodes and Storage Backends https://docs.clusterhq.com/en/latest/flocker-standalone/configuring-nodes-storage.html

flocker_cluster_name: my_flocker_cluster

The name of the cluster. This name will be used when creating the cluster certificates and, in the default case, the directory on the local machine where copies of the certs and keys are created.

# Warning: this folder will be deleted everytime the playbook is run
flocker_local_tempdir: /tmp/{{ flocker_cluster_name }}

The path to a folder that will be used to generate the cluster certificates and keys. This folder will not be cleaned up when the installation is finished. However, the folder will be deleted and recreated at the start of every provisioning run.

flocker_api_cert_name: api_user

A unique identifier for the API client.

flocker_install_docker_plugin: True

Set to True to install the Flocker Plugin for Docker.

## Example Playbook

---
- hosts: nodes
user: ubuntu
roles:
- role: ClusterHQ.flocker

## Example Invocation

ansible-playbook -i inventory/hosts flocker_example_playbook.yml --extra-vars "flocker_agent_yml_path=/home/user/config_files/agent.yml"

## Example Inventory

[flocker_control_service]
computer1.example.com

[flocker_agents]
computer2.example.com
computer3.example.com

[nodes:children]
flocker_control_service
flocker_agents

## License

MIT / BSD
19 changes: 19 additions & 0 deletions ansible/library/ClusterHQ.flocker/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---

# we have to configure the control service node and agent nodes
# differently. To accomplish this we choose what to import based on
# the host's inventory group name. Change these variables based what
# you have named the inventory groups for these servers.
flocker_control_service_groupname: flocker_control_service
flocker_agents_groupname: flocker_agents
flocker_docker_plugin_groupname: flocker_docker_plugin
flocker_ceph_groupname: flocker_ceph

# you must provide the absolute path to your flocker agent.yml file.
flocker_agent_yml_path: ""

flocker_cluster_name: my_flocker_cluster
# Warning: this folder will be deleted everytime the playbook is run
flocker_local_tempdir: /tmp/{{ flocker_cluster_name }}
flocker_api_cert_name: api_user
flocker_install_docker_plugin: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
start on runlevel [2345]
stop on runlevel [016]
Loading