From 75d3f7842d34a4c539d6360f3d340794515e6ce2 Mon Sep 17 00:00:00 2001 From: nesh Date: Tue, 27 Jun 2017 17:48:53 +0200 Subject: [PATCH 1/4] Added support for the conf.d like file layout using assemble task. Fixed .travis.yml after trusty image upgrade. --- .travis.yml | 1 + tasks/main.yml | 42 ++++++++++++++++++++++++++++++++++++++++-- vars/main.yml | 5 +++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index be22f0c6..3f4e5f30 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ --- sudo: required dist: trusty +group: deprecated-2017Q2 language: python python: "2.7" diff --git a/tasks/main.yml b/tasks/main.yml index 56fd5700..d59c351d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -67,15 +67,53 @@ - haproxy-configuration - haproxy-configuration-ssl +- name: create configuration folder + file: + path: "{{ haproxy_cfg_path }}" + state: directory + owner: root + group: root + mode: 0750 + tags: + - configuration + - haproxy + - haproxy-configuration + - name: update configuration file template: src: etc/haproxy/haproxy.cfg.j2 - dest: /etc/haproxy/haproxy.cfg + dest: "{{ haproxy_main_cfg_part }}" owner: root group: root mode: 0640 - validate: 'haproxy -f %s -c' + validate: "{{ haproxy_validation_command }}" + notify: restart haproxy + tags: + - configuration + - haproxy + - haproxy-configuration + +- name: assemble haproxy + assemble: + ignore_hidden: true + src: "{{ haproxy_cfg_path }}" + dest: "{{ haproxy_main_cfg }}" + delimiter: "### START FRAGMENT ###" + validate: "{{ haproxy_validation_command }}" + notify: restart haproxy + when: ansible_version | version_compare('2.0', '>=') + tags: + - configuration + - haproxy + - haproxy-configuration + +- name: assemble haproxy (ansible_version < 2.0) + assemble: + src: "{{ haproxy_cfg_path }}" + dest: "{{ haproxy_main_cfg }}" + delimiter: "### START FRAGMENT ###" notify: restart haproxy + when: ansible_version | version_compare('2.0', '<') tags: - configuration - haproxy diff --git a/vars/main.yml b/vars/main.yml index e4c52c8c..b4bfd4e1 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -6,3 +6,8 @@ haproxy_versions_supported: - 1.7 haproxy_ppa: "ppa:vbernat/haproxy-{{ haproxy_version }}" + +haproxy_cfg_path: /etc/haproxy/conf.d +haproxy_main_cfg_part: /etc/haproxy/conf.d/00-haproxy.cfg +haproxy_main_cfg: /etc/haproxy/haproxy.cfg +haproxy_validation_command: 'haproxy -f %s -c' From 679462f42ffea20c213d224290ffe3a464b083b7 Mon Sep 17 00:00:00 2001 From: nesh Date: Tue, 27 Jun 2017 18:00:19 +0200 Subject: [PATCH 2/4] Better task names and spacing cleanup. --- tasks/main.yml | 4 ++-- vars/main.yml | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index d59c351d..35cc207d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -93,7 +93,7 @@ - haproxy - haproxy-configuration -- name: assemble haproxy +- name: assemble haproxy configuration file assemble: ignore_hidden: true src: "{{ haproxy_cfg_path }}" @@ -107,7 +107,7 @@ - haproxy - haproxy-configuration -- name: assemble haproxy (ansible_version < 2.0) +- name: assemble haproxy configuration file (ansible < 2.0) assemble: src: "{{ haproxy_cfg_path }}" dest: "{{ haproxy_main_cfg }}" diff --git a/vars/main.yml b/vars/main.yml index b4bfd4e1..251addad 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -7,7 +7,7 @@ haproxy_versions_supported: haproxy_ppa: "ppa:vbernat/haproxy-{{ haproxy_version }}" -haproxy_cfg_path: /etc/haproxy/conf.d -haproxy_main_cfg_part: /etc/haproxy/conf.d/00-haproxy.cfg -haproxy_main_cfg: /etc/haproxy/haproxy.cfg +haproxy_cfg_path: /etc/haproxy/conf.d +haproxy_main_cfg_part: /etc/haproxy/conf.d/00-haproxy.cfg +haproxy_main_cfg: /etc/haproxy/haproxy.cfg haproxy_validation_command: 'haproxy -f %s -c' From c7633be7121ff4ce156714a1ed4afca39e2e0ff7 Mon Sep 17 00:00:00 2001 From: nesh Date: Tue, 27 Jun 2017 21:36:55 +0200 Subject: [PATCH 3/4] Fixed version comparation. Moved haproxy_cfg_path into defaults. --- defaults/main.yml | 3 +++ tasks/main.yml | 4 ++-- vars/main.yml | 3 +-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 33c2547b..0f761851 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -70,3 +70,6 @@ haproxy_frontend: [] # back-end section haproxy_backend: [] + +# conf.d location +haproxy_cfg_path: /etc/haproxy/conf.d diff --git a/tasks/main.yml b/tasks/main.yml index 35cc207d..b3cdc0e1 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -101,7 +101,7 @@ delimiter: "### START FRAGMENT ###" validate: "{{ haproxy_validation_command }}" notify: restart haproxy - when: ansible_version | version_compare('2.0', '>=') + when: ansible_version.full | version_compare('2.0', 'ge') tags: - configuration - haproxy @@ -113,7 +113,7 @@ dest: "{{ haproxy_main_cfg }}" delimiter: "### START FRAGMENT ###" notify: restart haproxy - when: ansible_version | version_compare('2.0', '<') + when: ansible_version.full | version_compare('2.0', 'lt') tags: - configuration - haproxy diff --git a/vars/main.yml b/vars/main.yml index 251addad..5159b6f2 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -7,7 +7,6 @@ haproxy_versions_supported: haproxy_ppa: "ppa:vbernat/haproxy-{{ haproxy_version }}" -haproxy_cfg_path: /etc/haproxy/conf.d -haproxy_main_cfg_part: /etc/haproxy/conf.d/00-haproxy.cfg +haproxy_main_cfg_part: "{{ haproxy_cfg_path }}/00-haproxy.cfg" haproxy_main_cfg: /etc/haproxy/haproxy.cfg haproxy_validation_command: 'haproxy -f %s -c' From 0607ce732430c516e5718c05d6f59cf5b0a3db4a Mon Sep 17 00:00:00 2001 From: nesh Date: Wed, 28 Jun 2017 13:50:44 +0200 Subject: [PATCH 4/4] Vagrant test for all distro/version combinations. Usefull while testing in local. --- Vagrantfile.full | 105 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Vagrantfile.full diff --git a/Vagrantfile.full b/Vagrantfile.full new file mode 100644 index 00000000..40b2f3cd --- /dev/null +++ b/Vagrantfile.full @@ -0,0 +1,105 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby ts=2 sw=2 tw=0 et : + +role = File.basename(File.expand_path(File.dirname(__FILE__))) + +ansible_versions = [ + 'latest', + '2.3.1.0', + '2.3.0.0', + '2.2.3.0', + '2.2.2.0', + '2.2.1.0', + '2.2.0.0', + '2.1.6', + '2.1.5', + '2.1.4', + '2.1.3', + '2.1.2', + '2.1.1.0', + '2.1.0.0', + '2.0.2.0', + '2.0.1.0', + '2.0.0.2', + '2.0.0.1', + '2.0.0.0', + '1.9.6', +] + +os_versions = [ + { + :name => "ubuntu-1204", + :box => "bento/ubuntu-12.04", + }, + { + :name => "ubuntu-1404", + :box => "bento/ubuntu-14.04", + }, + { + :name => "ubuntu-1604", + :box => "bento/ubuntu-16.04", + }, +] + +boxes = [] + +ip = 5 +os_versions.each do |os| + ansible_versions.reverse.each do |v| + boxes << { + :name => "ansible-#{v}-#{os[:name]}", + :box => os[:box], + :ip => "10.0.0.#{ip}", + :ansible_version => v + } + ip += 1 + end +end + +Vagrant.configure("2") do |config| + boxes.each do |box| + config.vm.define box[:name] do |vms| + vms.vm.box = box[:box] + + if Vagrant.has_plugin?("vagrant-cachier") + # Configure cached packages to be shared between instances of the same base box. + # More info on http://fgrehm.viewdocs.io/vagrant-cachier/usage + vms.cache.scope = :box + end + + vms.vm.hostname = box[:name] + + vms.vm.provider "virtualbox" do |v| + v.customize ["modifyvm", :id, "--cpuexecutioncap", "90"] + v.linked_clone = true + v.memory = 256 + v.cpus = 2 + end + + vms.vm.network :private_network, ip: box[:ip] + + vms.vm.provision "shell", + inline: "apt-get -qq -y install wget" + + vms.vm.provision "ansible_local" do |ansible| + ansible.version = box[:ansible_version] + ansible.install_mode = "pip" + ansible.playbook = "tests/vagrant.yml" + end + + # tests ported from travis + vms.vm.provision "shell", + inline: 'ansible-playbook -i /vagrant/tests/inventory /vagrant/tests/test.yml --syntax-check' + + vms.vm.provision "shell", + inline: "ansible-playbook -i /vagrant/tests/inventory /vagrant/tests/test.yml -vvvv" + + vms.vm.provision "shell", + inline: "ansible-playbook -i /vagrant/tests/inventory /vagrant/tests/test.yml | grep -q 'changed=0.*failed=0' && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1)" + + vms.vm.provision "shell", + inline: "wget http://localhost -O /dev/null -S --quiet 2>&1 | grep -q '503 Service Unavailable' && (echo 'Availability test: pass' && exit 0) || (echo 'Availability test: fail' && exit 1)" + + end + end +end