From 31411b64f185858144c4c1a0f09d0d6b4800931b Mon Sep 17 00:00:00 2001 From: "Scott S. Lowe" Date: Fri, 23 Sep 2016 17:19:16 -0600 Subject: [PATCH 1/6] Commit initial set of files for an OVN-Docker environment Commit an initial set of files (Vagrantfile, machines.yml) and Ansible playbooks (update.yml, provision.yml, config.json.j2, consul.conf, ansible.cfg) for turning up an OVN-Docker cluster of 3 VMs. --- ovn-docker-ansible/Vagrantfile | 70 ++++++++++++ ovn-docker-ansible/ansible.cfg | 5 + ovn-docker-ansible/config.json.j2 | 19 ++++ ovn-docker-ansible/consul.conf | 21 ++++ ovn-docker-ansible/machines.yml | 19 ++++ ovn-docker-ansible/provision.yml | 183 ++++++++++++++++++++++++++++++ ovn-docker-ansible/update.yml | 10 ++ 7 files changed, 327 insertions(+) create mode 100644 ovn-docker-ansible/Vagrantfile create mode 100644 ovn-docker-ansible/ansible.cfg create mode 100644 ovn-docker-ansible/config.json.j2 create mode 100644 ovn-docker-ansible/consul.conf create mode 100644 ovn-docker-ansible/machines.yml create mode 100644 ovn-docker-ansible/provision.yml create mode 100644 ovn-docker-ansible/update.yml diff --git a/ovn-docker-ansible/Vagrantfile b/ovn-docker-ansible/Vagrantfile new file mode 100644 index 0000000..90177fb --- /dev/null +++ b/ovn-docker-ansible/Vagrantfile @@ -0,0 +1,70 @@ +# -*- 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['vmw_box'] + + # 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'] + + # Assign additional private network + if machine['ip_addr'] != nil + srv.vm.network 'private_network', ip: machine['ip_addr'] + end # if machine['ip_addr'] + + # 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['vb_box'] + end # srv.vm.provider 'virtualbox' + end # config.vm.define + end # machines.each + + # Provision the VM with Ansible + config.vm.provision 'ansible' do |ansible| + ansible.playbook = 'update.yml' + end # config.vm.provision +end # Vagrant.configure diff --git a/ovn-docker-ansible/ansible.cfg b/ovn-docker-ansible/ansible.cfg new file mode 100644 index 0000000..e7c5f46 --- /dev/null +++ b/ovn-docker-ansible/ansible.cfg @@ -0,0 +1,5 @@ +[defaults] +inventory = .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory +private_key_file = ~/.vagrant.d/insecure_private_key +remote_user = vagrant +host_key_checking = False \ No newline at end of file diff --git a/ovn-docker-ansible/config.json.j2 b/ovn-docker-ansible/config.json.j2 new file mode 100644 index 0000000..a4d89ae --- /dev/null +++ b/ovn-docker-ansible/config.json.j2 @@ -0,0 +1,19 @@ +{% set lbracket = "[" %} +{% set rbracket = "]" %} +{% set quote = '"' %} + +{ + "bootstrap_expect": 3, + "server": true, + "datacenter": "dc1", + "data_dir": "/var/consul", + "log_level": "INFO", + "enable_syslog": false, + "retry_join": [ {% for host in groups['all'] %}{% if not loop.last %} +"{{ hostvars[host]['ansible_eth1']['ipv4']['address'] }}", + {% else %} +"{{ hostvars[host]['ansible_eth1']['ipv4']['address'] }}" + {% endif %}{% endfor %} ], + "client_addr": "0.0.0.0", + "advertise_addr": "{{ hostvars[inventory_hostname]['ansible_eth1']['ipv4']['address'] }}" +} diff --git a/ovn-docker-ansible/consul.conf b/ovn-docker-ansible/consul.conf new file mode 100644 index 0000000..60fa820 --- /dev/null +++ b/ovn-docker-ansible/consul.conf @@ -0,0 +1,21 @@ +description "Consul server process" + +start on runlevel [2345] +stop on runlevel [!2345] + +respawn + +script + if [ -f "/etc/service/consul" ]; then + . /etc/service/consul + fi + +export GOMAXPROCS=`nproc` +BIND_ADDR=`hostname -I | cut -f2 -d' '` + +exec /usr/local/bin/consul agent \ + -config-dir="/etc/consul.d/server" \ + -bind $BIND_ADDR \ + ${CONSUL_FLAGS} \ + >>/var/log/consul.log 2>&1 +end script diff --git a/ovn-docker-ansible/machines.yml b/ovn-docker-ansible/machines.yml new file mode 100644 index 0000000..432c200 --- /dev/null +++ b/ovn-docker-ansible/machines.yml @@ -0,0 +1,19 @@ +--- +- name: "docker-01" + vmw_box: "slowe/ubuntu-trusty-x64" + vb_box: "ubuntu/trusty64" + ram: "512" + vcpu: "1" + ip_addr: 192.168.100.101 +- name: "docker-02" + vmw_box: "slowe/ubuntu-trusty-x64" + vb_box: "ubuntu/trusty64" + ram: "512" + vcpu: "1" + ip_addr: 192.168.100.102 +- name: "docker-03" + vmw_box: "slowe/ubuntu-trusty-x64" + vb_box: "ubuntu/trusty64" + ram: "512" + vcpu: "1" + ip_addr: 192.168.100.103 diff --git a/ovn-docker-ansible/provision.yml b/ovn-docker-ansible/provision.yml new file mode 100644 index 0000000..f1130d2 --- /dev/null +++ b/ovn-docker-ansible/provision.yml @@ -0,0 +1,183 @@ +--- +- hosts: "all" + become: "yes" + remote_user: "vagrant" + + tasks: + - name: Install prerequisite packages + apt: + pkg: "{{ item }}" + state: "latest" + update_cache: "yes" + cache_valid_time: "3600" + with_items: + - "unzip" + - "python-pip" + - "libssl-dev" + - "libcap-ng-dev" + - "git" + - "libtool" + - "autoconf" + tags: + - consul + - packages + - ovn + + - name: Create consul group + group: + name: "consul" + state: "present" + tags: + - consul + + - name: Create user for Consul + user: + name: "consul" + group: "consul" + comment: "Consul daemon user" + shell: "/usr/sbin/nologin" + state: "present" + home: "/var/consul" + system: "yes" + createhome: "no" + tags: + - consul + + - name: Create Consul data and configuration directories + file: + path: "{{ item }}" + state: "directory" + owner: "consul" + group: "consul" + with_items: + - "/var/consul" + - "/etc/consul.d/server" + tags: + - consul + + - name: Download Consul package + get_url: + url: "https://releases.hashicorp.com/consul/0.7.0/consul_0.7.0_linux_amd64.zip" + dest: "/tmp/consul_0.7.0_linux_amd64.zip" + tags: + - consul + + - name: Unzip downloaded Consul file + unarchive: + copy: "no" + src: "/tmp/consul_0.7.0_linux_amd64.zip" + dest: "/usr/local/bin/" + creates: "/usr/local/bin/consul" + tags: + - consul + + - name: Install Upstart script for Consul + copy: + src: "consul.conf" + dest: "/etc/init/consul.conf" + owner: "root" + group: "root" + mode: "0644" + tags: + - consul + + - name: Install Consul configuration file + template: + src: "config.json.j2" + dest: "/etc/consul.d/server/config.json" + owner: "consul" + group: "consul" + mode: "0644" + tags: + - consul + + - name: Start Consul service + service: + name: "consul" + state: "started" + tags: + - consul + + - name: Add Docker APT repository key + apt_key: + keyserver: p80.pool.sks-keyservers.net + id: 58118E89F3A912897C070ADBF76221572C52609D + state: "present" + tags: + - docker + - apt-cfg + + - name: Add Docker APT repository (Trusty) + apt_repository: + repo: "deb https://apt.dockerproject.org/repo ubuntu-trusty main" + state: "present" + when: ansible_distribution_release == "trusty" + tags: + - docker + - apt-cfg + + - name: Add Docker APT repository (Precise) + apt_repository: + repo: "deb https://apt.dockerproject.org/repo ubuntu-precise main" + state: "present" + when: ansible_distribution_release == "precise" + tags: + - docker + - apt-cfg + + - name: Install Docker packages + apt: + name: "{{ item }}" + state: "present" + update_cache: "yes" + cache_valid_time: "3600" + with_items: + - "docker-engine=1.11.2-0~trusty" + tags: + - docker + - packages + + - name: Customize Docker daemon configuration + lineinfile: + dest: "/etc/default/docker" + insertafter: '#DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"' + line: "DOCKER_OPTS='-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store=consul://127.0.0.1:8500 --cluster-advertise={{ ansible_eth1.ipv4.address }}:0'" + owner: "root" + group: "root" + mode: "0644" + tags: + - docker + - docker-cfg + + - name: Restart Docker daemon + service: + name: "docker" + state: "restarted" + tags: + - docker + - docker-cfg + + - name: Set Vagrant user to member of Docker group + user: + name: "vagrant" + groups: "docker" + append: "yes" + tags: + - docker + - docker-cfg + + - name: Install Python flask module + pip: + name: "Flask" + tags: + - docker + - ovn + + - name: Clone OVS repository + become: "no" + git: + repo: "https://github.com/openvswitch/ovs.git" + dest: "~/ovs" + update: "no" + tags: + - ovn diff --git a/ovn-docker-ansible/update.yml b/ovn-docker-ansible/update.yml new file mode 100644 index 0000000..c05596b --- /dev/null +++ b/ovn-docker-ansible/update.yml @@ -0,0 +1,10 @@ +--- +- hosts: "all" + become: "yes" + remote_user: "vagrant" + + tasks: + - name: Update package cache + apt: + update_cache: "yes" + cache_valid_time: "3600" From 70bb2e959eafcdfb28bf5c154372a00ff83dc085 Mon Sep 17 00:00:00 2001 From: "Scott S. Lowe" Date: Wed, 28 Sep 2016 23:14:22 -0600 Subject: [PATCH 2/6] Update files for OVS/OVN Update files based on additional testing. Add lines to Vagrantfile to use virtio NICs w/ VirtualBox. Re-arrange config keys in Consul configuration template. Add quotes to IP addresses in machines.yml. Update Ansible playbook in provision.yml to install Python OVS libraries. --- ovn-docker-ansible/Vagrantfile | 2 ++ ovn-docker-ansible/config.json.j2 | 8 ++++---- ovn-docker-ansible/machines.yml | 6 +++--- ovn-docker-ansible/provision.yml | 20 +++++++++++--------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/ovn-docker-ansible/Vagrantfile b/ovn-docker-ansible/Vagrantfile index 90177fb..f256539 100644 --- a/ovn-docker-ansible/Vagrantfile +++ b/ovn-docker-ansible/Vagrantfile @@ -59,6 +59,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| vb.memory = machine['ram'] vb.cpus = machine['vcpu'] override.vm.box = machine['vb_box'] + vb.customize ['modifyvm', :id, '--nictype1', 'virtio'] + vb.customize ['modifyvm', :id, '--nictype2', 'virtio'] end # srv.vm.provider 'virtualbox' end # config.vm.define end # machines.each diff --git a/ovn-docker-ansible/config.json.j2 b/ovn-docker-ansible/config.json.j2 index a4d89ae..d4241d1 100644 --- a/ovn-docker-ansible/config.json.j2 +++ b/ovn-docker-ansible/config.json.j2 @@ -3,17 +3,17 @@ {% set quote = '"' %} { + "advertise_addr": "{{ hostvars[inventory_hostname]['ansible_eth1']['ipv4']['address'] }}", "bootstrap_expect": 3, - "server": true, + "client_addr": "0.0.0.0", "datacenter": "dc1", "data_dir": "/var/consul", + "enable_syslog": true, "log_level": "INFO", - "enable_syslog": false, "retry_join": [ {% for host in groups['all'] %}{% if not loop.last %} "{{ hostvars[host]['ansible_eth1']['ipv4']['address'] }}", {% else %} "{{ hostvars[host]['ansible_eth1']['ipv4']['address'] }}" {% endif %}{% endfor %} ], - "client_addr": "0.0.0.0", - "advertise_addr": "{{ hostvars[inventory_hostname]['ansible_eth1']['ipv4']['address'] }}" + "server": true } diff --git a/ovn-docker-ansible/machines.yml b/ovn-docker-ansible/machines.yml index 432c200..3bbf0d8 100644 --- a/ovn-docker-ansible/machines.yml +++ b/ovn-docker-ansible/machines.yml @@ -4,16 +4,16 @@ vb_box: "ubuntu/trusty64" ram: "512" vcpu: "1" - ip_addr: 192.168.100.101 + ip_addr: "192.168.100.101" - name: "docker-02" vmw_box: "slowe/ubuntu-trusty-x64" vb_box: "ubuntu/trusty64" ram: "512" vcpu: "1" - ip_addr: 192.168.100.102 + ip_addr: "192.168.100.102" - name: "docker-03" vmw_box: "slowe/ubuntu-trusty-x64" vb_box: "ubuntu/trusty64" ram: "512" vcpu: "1" - ip_addr: 192.168.100.103 + ip_addr: "192.168.100.103" diff --git a/ovn-docker-ansible/provision.yml b/ovn-docker-ansible/provision.yml index f1130d2..7a8b65b 100644 --- a/ovn-docker-ansible/provision.yml +++ b/ovn-docker-ansible/provision.yml @@ -100,8 +100,8 @@ - name: Add Docker APT repository key apt_key: - keyserver: p80.pool.sks-keyservers.net - id: 58118E89F3A912897C070ADBF76221572C52609D + keyserver: "p80.pool.sks-keyservers.net" + id: "58118E89F3A912897C070ADBF76221572C52609D" state: "present" tags: - docker @@ -166,18 +166,20 @@ - docker - docker-cfg - - name: Install Python flask module + - name: Install Python modules pip: - name: "Flask" + name: "{{ item }}" + with_items: + - "Flask" + - "ovs" tags: - docker - ovn - - name: Clone OVS repository + - name: Download OVS 2.6.0 release tarball become: "no" - git: - repo: "https://github.com/openvswitch/ovs.git" - dest: "~/ovs" - update: "no" + get_url: + url: "https://github.com/openvswitch/ovs/archive/v2.6.0.tar.gz" + dest: "/home/vagrant/2.6.0.tar.gz" tags: - ovn From d581dba3a811200868819f1831ad9129faea887a Mon Sep 17 00:00:00 2001 From: "Scott S. Lowe" Date: Mon, 5 Dec 2016 22:40:02 -0700 Subject: [PATCH 3/6] Update based on OVN learning environment Update Vagrantfile, Ansible playbook (provision.yml), and machines.yml based on "plain" OVN learning environment Signed-off-by: Scott S. Lowe --- ovn-docker-ansible/Vagrantfile | 18 +++++--- ovn-docker-ansible/config.json.j2 | 6 +-- ovn-docker-ansible/machines.yml | 33 +++++++++----- ovn-docker-ansible/provision.yml | 74 ++++++++++++++++++++++--------- 4 files changed, 87 insertions(+), 44 deletions(-) diff --git a/ovn-docker-ansible/Vagrantfile b/ovn-docker-ansible/Vagrantfile index f256539..50e5183 100644 --- a/ovn-docker-ansible/Vagrantfile +++ b/ovn-docker-ansible/Vagrantfile @@ -31,7 +31,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| srv.vm.hostname = machine['name'] # Specify the Vagrant box to use (use VMware box by default) - srv.vm.box = machine['vmw_box'] + srv.vm.box = machine['box']['vmw'] # Configure default synced folder (disable by default) if machine['sync_disabled'] != nil @@ -40,10 +40,14 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| srv.vm.synced_folder '.', '/vagrant', disabled: true end #if machine['sync_disabled'] - # Assign additional private network - if machine['ip_addr'] != nil - srv.vm.network 'private_network', ip: machine['ip_addr'] - end # if machine['ip_addr'] + # 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| @@ -58,7 +62,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| srv.vm.provider 'virtualbox' do |vb, override| vb.memory = machine['ram'] vb.cpus = machine['vcpu'] - override.vm.box = machine['vb_box'] + override.vm.box = machine['box']['vb'] vb.customize ['modifyvm', :id, '--nictype1', 'virtio'] vb.customize ['modifyvm', :id, '--nictype2', 'virtio'] end # srv.vm.provider 'virtualbox' @@ -67,6 +71,6 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # Provision the VM with Ansible config.vm.provision 'ansible' do |ansible| - ansible.playbook = 'update.yml' + ansible.playbook = 'provision.yml' end # config.vm.provision end # Vagrant.configure diff --git a/ovn-docker-ansible/config.json.j2 b/ovn-docker-ansible/config.json.j2 index d4241d1..cb4157a 100644 --- a/ovn-docker-ansible/config.json.j2 +++ b/ovn-docker-ansible/config.json.j2 @@ -3,7 +3,7 @@ {% set quote = '"' %} { - "advertise_addr": "{{ hostvars[inventory_hostname]['ansible_eth1']['ipv4']['address'] }}", + "advertise_addr": "{{ hostvars[inventory_hostname]['ansible_enp0s8']['ipv4']['address'] }}", "bootstrap_expect": 3, "client_addr": "0.0.0.0", "datacenter": "dc1", @@ -11,9 +11,9 @@ "enable_syslog": true, "log_level": "INFO", "retry_join": [ {% for host in groups['all'] %}{% if not loop.last %} -"{{ hostvars[host]['ansible_eth1']['ipv4']['address'] }}", +"{{ hostvars[host]['ansible_enp0s8']['ipv4']['address'] }}", {% else %} -"{{ hostvars[host]['ansible_eth1']['ipv4']['address'] }}" +"{{ hostvars[host]['ansible_enp0s8']['ipv4']['address'] }}" {% endif %}{% endfor %} ], "server": true } diff --git a/ovn-docker-ansible/machines.yml b/ovn-docker-ansible/machines.yml index 3bbf0d8..67e2cc2 100644 --- a/ovn-docker-ansible/machines.yml +++ b/ovn-docker-ansible/machines.yml @@ -1,19 +1,28 @@ --- -- name: "docker-01" - vmw_box: "slowe/ubuntu-trusty-x64" - vb_box: "ubuntu/trusty64" +- box: + vmw: "bento/ubuntu-16.04" + vb: "bento/ubuntu-16.04" + name: "docker-01" + nics: + - type: "private_network" + ip_addr: "192.168.100.101" ram: "512" vcpu: "1" - ip_addr: "192.168.100.101" -- name: "docker-02" - vmw_box: "slowe/ubuntu-trusty-x64" - vb_box: "ubuntu/trusty64" +- box: + vmw: "bento/ubuntu-16.04" + vb: "bento/ubuntu-16.04" + name: "docker-02" + nics: + - type: "private_network" + ip_addr: "192.168.100.102" ram: "512" vcpu: "1" - ip_addr: "192.168.100.102" -- name: "docker-03" - vmw_box: "slowe/ubuntu-trusty-x64" - vb_box: "ubuntu/trusty64" +- box: + vmw: "bento/ubuntu-16.04" + vb: "bento/ubuntu-16.04" + name: "docker-03" + nics: + - type: "private_network" + ip_addr: "192.168.100.103" ram: "512" vcpu: "1" - ip_addr: "192.168.100.103" diff --git a/ovn-docker-ansible/provision.yml b/ovn-docker-ansible/provision.yml index 7a8b65b..ff903b9 100644 --- a/ovn-docker-ansible/provision.yml +++ b/ovn-docker-ansible/provision.yml @@ -18,6 +18,7 @@ - "git" - "libtool" - "autoconf" + - "ubuntu-cloud-keyring" tags: - consul - packages @@ -57,15 +58,15 @@ - name: Download Consul package get_url: - url: "https://releases.hashicorp.com/consul/0.7.0/consul_0.7.0_linux_amd64.zip" - dest: "/tmp/consul_0.7.0_linux_amd64.zip" + url: "https://releases.hashicorp.com/consul/0.7.1/consul_0.7.1_linux_amd64.zip" + dest: "/tmp/consul_0.7.1_linux_amd64.zip" tags: - consul - name: Unzip downloaded Consul file unarchive: copy: "no" - src: "/tmp/consul_0.7.0_linux_amd64.zip" + src: "/tmp/consul_0.7.1_linux_amd64.zip" dest: "/usr/local/bin/" creates: "/usr/local/bin/consul" tags: @@ -107,20 +108,12 @@ - docker - apt-cfg - - name: Add Docker APT repository (Trusty) + - name: Add Docker APT repository (Xenial) apt_repository: - repo: "deb https://apt.dockerproject.org/repo ubuntu-trusty main" + repo: "deb https://apt.dockerproject.org/repo ubuntu-xenial main" + update_cache: "yes" state: "present" - when: ansible_distribution_release == "trusty" - tags: - - docker - - apt-cfg - - - name: Add Docker APT repository (Precise) - apt_repository: - repo: "deb https://apt.dockerproject.org/repo ubuntu-precise main" - state: "present" - when: ansible_distribution_release == "precise" + when: ansible_distribution_release == "xenial" tags: - docker - apt-cfg @@ -132,7 +125,7 @@ update_cache: "yes" cache_valid_time: "3600" with_items: - - "docker-engine=1.11.2-0~trusty" + - "docker-engine=1.11.2-0~xenial" tags: - docker - packages @@ -141,7 +134,7 @@ lineinfile: dest: "/etc/default/docker" insertafter: '#DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"' - line: "DOCKER_OPTS='-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store=consul://127.0.0.1:8500 --cluster-advertise={{ ansible_eth1.ipv4.address }}:0'" + line: "DOCKER_OPTS='-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store=consul://127.0.0.1:8500 --cluster-advertise={{ ansible_enp0s8.ipv4.address }}:0'" owner: "root" group: "root" mode: "0644" @@ -176,10 +169,47 @@ - docker - ovn - - name: Download OVS 2.6.0 release tarball - become: "no" - get_url: - url: "https://github.com/openvswitch/ovs/archive/v2.6.0.tar.gz" - dest: "/home/vagrant/2.6.0.tar.gz" + - name: "Add Ubuntu Cloud Archive repository" + apt_repository: + repo: "{{ item }}" + state: "present" + update_cache: "yes" + with_items: + - "deb http://ubuntu-cloud.archive.canonical.com/ubuntu xenial-updates/newton main" + tags: + - ovn + - apt-cfg + + - name: "Install OVS/OVN 2.6.0" + apt: + state: "present" + update_cache: "no" + name: "{{ item }}" + with_items: + - "ovn-common" + - "ovn-host" + - "openvswitch-common" + - "openvswitch-switch" + tags: + - ovn + - packages + + - name: "Install central OVN components" + apt: + state: "present" + update_cache: "no" + name: "ovn-central" + when: ansible_hostname == "docker-01" + tags: + - ovn + - packages + + - name: "Install configuration script" + template: + src: "setup.sh.j2" + dest: "/home/vagrant/setup.sh" + owner: "vagrant" + group: "vagrant" + mode: "0755" tags: - ovn From 72a72560fb245681672127488d12d3c0515104f3 Mon Sep 17 00:00:00 2001 From: "Scott S. Lowe" Date: Tue, 6 Dec 2016 03:42:05 -0700 Subject: [PATCH 4/6] Add systemd compatibility Remove old Upstart job file. Add systemd unit file. Edit Consul configuration file template to address systemd compatibility. Modify Ansible playbook to address systemd compatibility. Add missing OVN setup script. Remove unneeded files. Signed-off-by: Scott S. Lowe --- ovn-docker-ansible/config.json.j2 | 1 + ovn-docker-ansible/consul-server.service | 17 +++++++++++++++++ ovn-docker-ansible/consul.conf | 21 --------------------- ovn-docker-ansible/provision.yml | 12 ++++++++---- ovn-docker-ansible/setup.sh.j2 | 14 ++++++++++++++ ovn-docker-ansible/update.yml | 10 ---------- 6 files changed, 40 insertions(+), 35 deletions(-) create mode 100644 ovn-docker-ansible/consul-server.service delete mode 100644 ovn-docker-ansible/consul.conf create mode 100644 ovn-docker-ansible/setup.sh.j2 delete mode 100644 ovn-docker-ansible/update.yml diff --git a/ovn-docker-ansible/config.json.j2 b/ovn-docker-ansible/config.json.j2 index cb4157a..09739cd 100644 --- a/ovn-docker-ansible/config.json.j2 +++ b/ovn-docker-ansible/config.json.j2 @@ -4,6 +4,7 @@ { "advertise_addr": "{{ hostvars[inventory_hostname]['ansible_enp0s8']['ipv4']['address'] }}", + "bind_addr": "{{ hostvars[inventory_hostname]['ansible_enp0s8']['ipv4']['address'] }}", "bootstrap_expect": 3, "client_addr": "0.0.0.0", "datacenter": "dc1", diff --git a/ovn-docker-ansible/consul-server.service b/ovn-docker-ansible/consul-server.service new file mode 100644 index 0000000..a1f6fe3 --- /dev/null +++ b/ovn-docker-ansible/consul-server.service @@ -0,0 +1,17 @@ +[Unit] +Description=Consul Server +Requires=network-online.target +After=network-online.target + +[Service] +User=consul +Group=consul +Environment="GOMAXPROCS=2" +Restart=on-failure +RestartSec=1 +ExecReload=/bin/kill -HUP $MAINPID +KillSignal=SIGINT +ExecStart=/usr/local/bin/consul agent -config-dir=/etc/consul.d/server + +[Install] +WantedBy=multi-user.target diff --git a/ovn-docker-ansible/consul.conf b/ovn-docker-ansible/consul.conf deleted file mode 100644 index 60fa820..0000000 --- a/ovn-docker-ansible/consul.conf +++ /dev/null @@ -1,21 +0,0 @@ -description "Consul server process" - -start on runlevel [2345] -stop on runlevel [!2345] - -respawn - -script - if [ -f "/etc/service/consul" ]; then - . /etc/service/consul - fi - -export GOMAXPROCS=`nproc` -BIND_ADDR=`hostname -I | cut -f2 -d' '` - -exec /usr/local/bin/consul agent \ - -config-dir="/etc/consul.d/server" \ - -bind $BIND_ADDR \ - ${CONSUL_FLAGS} \ - >>/var/log/consul.log 2>&1 -end script diff --git a/ovn-docker-ansible/provision.yml b/ovn-docker-ansible/provision.yml index ff903b9..32dfa05 100644 --- a/ovn-docker-ansible/provision.yml +++ b/ovn-docker-ansible/provision.yml @@ -72,10 +72,10 @@ tags: - consul - - name: Install Upstart script for Consul + - name: Install systemd unit for Consul copy: - src: "consul.conf" - dest: "/etc/init/consul.conf" + src: "consul-server.service" + dest: "/etc/systemd/system/consul-server.service" owner: "root" group: "root" mode: "0644" @@ -92,9 +92,12 @@ tags: - consul + - name: Reload systemd units + command: "systemctl daemon-reload" + - name: Start Consul service service: - name: "consul" + name: "consul-server" state: "started" tags: - consul @@ -188,6 +191,7 @@ with_items: - "ovn-common" - "ovn-host" + - "ovn-docker" - "openvswitch-common" - "openvswitch-switch" tags: diff --git a/ovn-docker-ansible/setup.sh.j2 b/ovn-docker-ansible/setup.sh.j2 new file mode 100644 index 0000000..6ad54ce --- /dev/null +++ b/ovn-docker-ansible/setup.sh.j2 @@ -0,0 +1,14 @@ +#!/bin/bash + +# Stop the ovn-controller daemon +sudo /usr/share/openvswitch/scripts/ovn-ctl stop_controller + +# Configure OVS +sudo ovs-vsctl set Open_vSwitch . \ + external_ids:ovn-remote="tcp:192.168.100.101:6642" \ + external_ids:ovn-nb="tcp:192.168.100.101:6641" \ + external_ids:ovn-encap-ip={{ ansible_enp0s8.ipv4.address }} \ + external_ids:ovn-encap-type="geneve" + +# Start the ovn-controller daemon +sudo /usr/share/openvswitch/scripts/ovn-ctl start_controller diff --git a/ovn-docker-ansible/update.yml b/ovn-docker-ansible/update.yml deleted file mode 100644 index c05596b..0000000 --- a/ovn-docker-ansible/update.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- hosts: "all" - become: "yes" - remote_user: "vagrant" - - tasks: - - name: Update package cache - apt: - update_cache: "yes" - cache_valid_time: "3600" From 96a07a48e3b0316a488c1c210c1691e6bc101a8b Mon Sep 17 00:00:00 2001 From: "Scott S. Lowe" Date: Tue, 6 Dec 2016 20:30:25 -0700 Subject: [PATCH 5/6] Finalize systemd compatibility Add Jinja2 template for systemd drop-in file to customize Docker daemon behavior. Edit Ansible playbook to support use of systemd drop-in files. Signed-off-by: Scott S. Lowe --- ovn-docker-ansible/10-exec-options.conf.j2 | 5 +++++ ovn-docker-ansible/provision.yml | 21 +++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 ovn-docker-ansible/10-exec-options.conf.j2 diff --git a/ovn-docker-ansible/10-exec-options.conf.j2 b/ovn-docker-ansible/10-exec-options.conf.j2 new file mode 100644 index 0000000..5bf0cd7 --- /dev/null +++ b/ovn-docker-ansible/10-exec-options.conf.j2 @@ -0,0 +1,5 @@ +[Service] +ExecStart= +ExecStart=/usr/bin/docker daemon -H fd:// -H tcp://0.0.0.0:2375 \ + --cluster-store=consul://127.0.0.1:8500 \ + --cluster-advertise={{ ansible_enp0s8.ipv4.address }}:0 diff --git a/ovn-docker-ansible/provision.yml b/ovn-docker-ansible/provision.yml index 32dfa05..b836c93 100644 --- a/ovn-docker-ansible/provision.yml +++ b/ovn-docker-ansible/provision.yml @@ -133,11 +133,21 @@ - docker - packages + - name: Create systemd drop-in directory + file: + path: "/etc/systemd/system/docker.service.d" + state: "directory" + owner: "root" + group: "root" + mode: "0755" + tags: + - docker + - docker-cfg + - name: Customize Docker daemon configuration - lineinfile: - dest: "/etc/default/docker" - insertafter: '#DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"' - line: "DOCKER_OPTS='-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store=consul://127.0.0.1:8500 --cluster-advertise={{ ansible_enp0s8.ipv4.address }}:0'" + template: + src: "10-exec-options.conf.j2" + dest: "/etc/systemd/system/docker.service.d/10-exec-options.conf" owner: "root" group: "root" mode: "0644" @@ -145,6 +155,9 @@ - docker - docker-cfg + - name: Reload systemd units + command: "systemctl daemon-reload" + - name: Restart Docker daemon service: name: "docker" From f8a5de9471bbd6590f191dd5b95f775c2b0505ac Mon Sep 17 00:00:00 2001 From: "Scott S. Lowe" Date: Tue, 6 Dec 2016 20:50:29 -0700 Subject: [PATCH 6/6] Add README.md Add README.md to the learning environment. Signed-off-by: Scott S. Lowe --- ovn-docker-ansible/README.md | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 ovn-docker-ansible/README.md diff --git a/ovn-docker-ansible/README.md b/ovn-docker-ansible/README.md new file mode 100644 index 0000000..9473d08 --- /dev/null +++ b/ovn-docker-ansible/README.md @@ -0,0 +1,47 @@ +# Open Virtual Network (OVN) with Docker + +These files were created to allow users to use Vagrant ([http://www.vagrantup.com](http://www.vagrantup.com)) to quickly and easily spin up an environment to test Open Virtual Network (OVN), a part of the Open vSwitch project, to provide overlay networking for Docker containers. + +## Contents + +* **10-exec-options.conf.j2**: This Jinja2 template is used to create a systemd drop-in file to customize the default behavior of the Docker Engine. The file created by this template is placed by Ansible at `/etc/systemd/system/docker.service.d`. + +* **ansible.cfg**: This is an Ansible configuration file that instructs Ansible to use the "vagrant" remote user, and to use Vagrant's built-in Ansible inventory. + +* **config.json.j2**: This Jinja2 template is used to create a Consul configuration file to turn up the Consul cluster. The configuration file created from this template is placed at `/etc/consul.d/server`. + +* **consul-server.service**: This is a systemd unit file for the Consul cluster. + +* **machines.yml**: This YAML file contains a list of VM definitions and associated configuration data. It is referenced by `Vagrantfile` when Vagrant instantiates the VMs. + +* **provision.yml**: This Ansible playbook installs the OVS/OVN components on each Vagrant machine. It's called automatically by Vagrant. + +* **README.md**: This file you're currently reading. + +* **setup.sh.j2**: This Jinja2 template is used by Ansible to build a customized OVS/OVN configuration script for each Vagrant machine. The shell script created by this template is placed by Ansible in `/home/vagrant/setup.sh`. + +* **Vagrantfile**: This file is used by Vagrant to spin up the virtual machines. This file is fairly extensively commented to help explain what's happening. You should be able to use this file unchanged; all the VM configuration options are stored outside this file. + +## Instructions + +These instructions assume you've already installed Vagrant, your back-end virtualization provider (such as VMware Fusion or VirtualBox), and any necessary plugins (such as the Vagrant VMware plugin). Please refer to the documentation for those products for more information on installation or configuration. + +1. Use `vagrant box add` to add an Ubuntu 16.04 box to your system. The "bento/ubuntu-16.04" box is very good for both VirtualBox and VMware Fusion/Workstation. (Note that the "ubuntu/xenial64" box for VirtualBox is currently broken under Vagrant.) + +2. Edit the `machines.yml` file to ensure the box you downloaded in step 1 is specified on the "box:" sections of this file. Specify the name of a VMware-formatted box on the "vmw:" line; place the name of a VirtualBox-formatted box on the "vb:" line. + +3. Run `vagrant up` to have Vagrant instantiate the three machines configured by default in this environment, and provision them using Ansible. (Note you'll need Ansible installed locally on the system where you're running `vagrant up`.) + +4. Use `vagrant ssh ovn-01` to log into the first system. Run `sudo ./setup.sh` to perform final configuration steps for OVS/OVN. + +5. Repeat step #4 with `ovn-02` and `ovn-03`. At this point, OVN is up and running, with the OVN central components running on "ovn-01". + +6. To add Docker support to OVN, log into "ovn-01" and run `/usr/bin/ovn-docker-overlay-driver --detach`. This will launch the Docker driver for OVS/OVN. + +7. Repeat step #6 on "ovn-02" and "ovn-03". Your OVN environment now has Docker networking support. + +8. Create a Docker network using `docker network create -d openvswitch --subnet= `. You will note an OVN logical switch is created that corresponds to the Docker network. + +9. Launch a Docker container and attach it to the new network with `docker run -d --net= `. You will note OVN logical ports added to the OVN logical switch. + +Enjoy!