diff --git a/bootstrap/common.sh b/bootstrap/common.sh index d078e132..155fb0d2 100644 --- a/bootstrap/common.sh +++ b/bootstrap/common.sh @@ -87,6 +87,7 @@ open_urls() { /usr/bin/open "http://$(terraform output master.1.ip):8080" /usr/bin/open "http://$(terraform output master.1.ip):8500" /usr/bin/open "http://$(terraform output master.1.ip):4040" + /usr/bin/open "http://$(terraform output master.1.ip):8081" fi popd } diff --git a/roles/cadvisor/defaults/main.yml b/roles/cadvisor/defaults/main.yml new file mode 100644 index 00000000..bd74553c --- /dev/null +++ b/roles/cadvisor/defaults/main.yml @@ -0,0 +1,10 @@ +--- +# defaults file for cadvisor +cadvisor_enabled: true +cadvisor_version: 'latest' +cadvisor_host_port: 8081 +cadvisor_restart_policy: 'always' +cadvisor_net: 'bridge' +cadvisor_hostname: "{{ ansible_ssh_host }}" +cadvisor_image: "google/cadvisor:{{ cadvisor_version }}" +cadvisor_consul_dir: /etc/consul.d diff --git a/roles/cadvisor/handlers/main.yml b/roles/cadvisor/handlers/main.yml new file mode 100644 index 00000000..e69de29b diff --git a/roles/cadvisor/meta/main.yml b/roles/cadvisor/meta/main.yml new file mode 100644 index 00000000..bec4a0d5 --- /dev/null +++ b/roles/cadvisor/meta/main.yml @@ -0,0 +1,130 @@ +--- +galaxy_info: + author: Alberto Lamela + description: + company: Capgemini + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (MIT) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + - name: Ubuntu + versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + - trusty + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + categories: + - cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + - system + #- web +dependencies: + # - role: consul + # - role: registrator + # - role: zookeeper + # List your role dependencies here, one per line. Only + # dependencies available via galaxy should be listed here. + # Be sure to remove the '[]' above if you add dependencies + # to this list. diff --git a/roles/cadvisor/tasks/main.yml b/roles/cadvisor/tasks/main.yml new file mode 100644 index 00000000..579f46f4 --- /dev/null +++ b/roles/cadvisor/tasks/main.yml @@ -0,0 +1,64 @@ +# Install (docker-py) python package as is a docker module dependency. +- pip: name=docker-py version=1.1.0 + +# tasks for running cadvisor +- name: run cadvisor container + when: cadvisor_enabled + docker: + name: cadvisor + image: "{{ cadvisor_image }}" + state: started + restart_policy: "{{ cadvisor_restart_policy }}" + net: "{{ cadvisor_net }}" + ports: + - "{{ cadvisor_host_port }}:8080" + hostname: "{{ cadvisor_hostname }}" + volumes: + - "/var/lib/docker/:/var/lib/docker:ro" + - "/:/rootfs:ro" + - "/var/run:/var/run:rw" + - "/sys:/sys:ro" + tags: + - cadvisor + +- name: upload cadvisor template service + when: cadvisor_enabled + template: + src: cadvisor.conf.j2 + dest: /etc/init/cadvisor.conf + mode: 0755 + sudo: yes + tags: + - cadvisor + +# Attach to the running container, or start it if needed +# and forward all signals so that the process manager can detect +# when a container stops and correctly restart it. +- name: ensure cadvisor is running (and enable it at boot) + when: cadvisor_enabled + sudo: yes + service: + name: cadvisor + state: started + enabled: yes + tags: + - cadvisor + +- name: Set cadvisor consul service definition + sudo: yes + template: + src: cadvisor-consul.j2 + dest: "{{ cadvisor_consul_dir }}/cadvisor.json" + notify: + - restart consul + when: cadvisor_enabled + +- name: ensure cadvisor is running (and enable it at boot) + when: not cadvisor_enabled + sudo: yes + service: + name: cadvisor + state: stopped + enabled: yes + tags: + - cadvisor \ No newline at end of file diff --git a/roles/cadvisor/templates/cadvisor-consul.j2 b/roles/cadvisor/templates/cadvisor-consul.j2 new file mode 100644 index 00000000..71e644fa --- /dev/null +++ b/roles/cadvisor/templates/cadvisor-consul.j2 @@ -0,0 +1,11 @@ +{ + "service": { + "name": "cadvisor", + "tags": [ "cadvisor" ], + "port": {{ cadvisor_host_port }}, + "check": { + "script": "curl --silent --show-error --fail --dump-header /dev/stderr --retry 2 http://{{ cadvisor_hostname }}:{{ cadvisor_host_port}}", + "interval": "10s" + } + } +} \ No newline at end of file diff --git a/roles/cadvisor/templates/cadvisor.conf.j2 b/roles/cadvisor/templates/cadvisor.conf.j2 new file mode 100644 index 00000000..12ce045d --- /dev/null +++ b/roles/cadvisor/templates/cadvisor.conf.j2 @@ -0,0 +1,12 @@ +description "cadvisor container" + +start on started docker +stop on stopping docker + +script + /usr/bin/docker start -a cadvisor +end script + +respawn +respawn limit 10 10 +kill timeout 10 diff --git a/roles/cadvisor/vars/main.yml b/roles/cadvisor/vars/main.yml new file mode 100644 index 00000000..7d2f5bf5 --- /dev/null +++ b/roles/cadvisor/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for cadvisor diff --git a/roles/marathon/defaults/main.yml b/roles/marathon/defaults/main.yml index f905fefe..945b4548 100644 --- a/roles/marathon/defaults/main.yml +++ b/roles/marathon/defaults/main.yml @@ -1,5 +1,6 @@ --- # defaults file for marathon +marathon_consul_dir: /etc/consul.d marathon_enabled: true marathon_version: '0.8.2' marathon_restart_policy: 'always' diff --git a/roles/marathon/tasks/main.yml b/roles/marathon/tasks/main.yml index b71115e7..104eb2f4 100644 --- a/roles/marathon/tasks/main.yml +++ b/roles/marathon/tasks/main.yml @@ -75,6 +75,15 @@ tags: - marathon +- name: Set marathon consul service definition + sudo: yes + template: + src: marathon-consul.j2 + dest: "{{ marathon_consul_dir }}/marathon.json" + notify: + - restart consul + when: marathon_enabled + # tasks for stoping docker marathon - name: stop marathon container when: not marathon_enabled diff --git a/site.yml b/site.yml index dbc016fe..4cf17ac9 100644 --- a/site.yml +++ b/site.yml @@ -23,6 +23,7 @@ - docker - weave - registrator + - cadvisor - hosts: mesos_masters roles: diff --git a/tests/properties.yml b/tests/properties.yml index 3193e0d7..a1b31d06 100644 --- a/tests/properties.yml +++ b/tests/properties.yml @@ -8,6 +8,7 @@ mesos_masters: - weave - docker - registrator + - cadvisor mesos_slaves: :roles: - dnsmasq @@ -16,6 +17,8 @@ mesos_slaves: - weave - docker - registrator + - cadvisor load_balancers: :roles: - haproxy + - cadvisor diff --git a/tests/spec/cadvisor/cadvisor_spec.rb b/tests/spec/cadvisor/cadvisor_spec.rb new file mode 100644 index 00000000..d529c56d --- /dev/null +++ b/tests/spec/cadvisor/cadvisor_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe docker_container('cadvisor') do + it { should be_running } + it { should have_volume('/var/lib/docker','/var/lib/docker') } + it { should have_volume('/rootfs','/') } + it { should have_volume('/var/run','/var/run') } + it { should have_volume('/sys','/sys') } +end + +describe port(8081) do + it { should be_listening } +end + +describe service('cadvisor') do + it { should be_running } +end