From 4408a8d5143f699ff472c45d56aa9d3d27f3e519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Han?= Date: Tue, 28 Jul 2015 17:57:58 +0200 Subject: [PATCH] Re-arrange docker invocation and fix bootstrap restapi MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sébastien Han --- group_vars/restapis.sample | 1 + roles/ceph-restapi/defaults/main.yml | 1 + roles/ceph-restapi/tasks/docker.yml | 49 ------------------- .../tasks/docker/fetch_configs.yml | 26 ++++++++++ roles/ceph-restapi/tasks/docker/main.yml | 4 ++ .../tasks/docker/pre_requisite.yml | 6 +++ .../tasks/docker/start_docker_restapi.yml | 10 ++++ roles/ceph-restapi/tasks/main.yml | 2 +- 8 files changed, 49 insertions(+), 50 deletions(-) delete mode 100644 roles/ceph-restapi/tasks/docker.yml create mode 100644 roles/ceph-restapi/tasks/docker/fetch_configs.yml create mode 100644 roles/ceph-restapi/tasks/docker/main.yml create mode 100644 roles/ceph-restapi/tasks/docker/pre_requisite.yml create mode 100644 roles/ceph-restapi/tasks/docker/start_docker_restapi.yml diff --git a/group_vars/restapis.sample b/group_vars/restapis.sample index 2bb3591f3..777282943 100644 --- a/group_vars/restapis.sample +++ b/group_vars/restapis.sample @@ -13,3 +13,4 @@ dummy: #ceph_restapi_port: 5000 #ceph_restapi_docker_username: ceph #ceph_restapi_docker_imagename: daemon +#ceph_restapi_docker_extra_env: "RESTAPI_IP=0.0.0.0" # comma separated variables diff --git a/roles/ceph-restapi/defaults/main.yml b/roles/ceph-restapi/defaults/main.yml index ce86fa603..33bda1878 100644 --- a/roles/ceph-restapi/defaults/main.yml +++ b/roles/ceph-restapi/defaults/main.yml @@ -8,3 +8,4 @@ ceph_restapi_docker_interface: eth0 ceph_restapi_port: 5000 ceph_restapi_docker_username: ceph ceph_restapi_docker_imagename: daemon +ceph_restapi_docker_extra_env: "RESTAPI_IP=0.0.0.0" # comma separated variables diff --git a/roles/ceph-restapi/tasks/docker.yml b/roles/ceph-restapi/tasks/docker.yml deleted file mode 100644 index 268f82675..000000000 --- a/roles/ceph-restapi/tasks/docker.yml +++ /dev/null @@ -1,49 +0,0 @@ ---- -- name: set config and keys paths - set_fact: - ceph_config_keys: - - /etc/ceph/ceph.client.admin.keyring - - /etc/ceph/ceph.conf - -# NOTE (leseb): force version 1.1.0 because https://github.com/ansible/ansible-modules-core/issues/1227 -- name: install docker-py - pip: > - name=docker-py - version=1.1.0 - -- name: stat for ceph config and keys - stat: > - path={{ item }} - with_items: ceph_config_keys - ignore_errors: true - register: statconfig - -- name: try to fetch ceph config and keys - copy: > - src=fetch/docker_mon_files/"{{ item }}" - dest=/etc/ceph/ - owner=root - group=root - mode=600 - with_together: - - ceph_config_keys - - statconfig.results - when: item.1.stat.exists == true - -- name: run the ceph rest api docker image - docker: > - image="{{ ceph_restapi_docker_username }}/{{ ceph_restapi_docker_imagename }}" - name={{ ansible_hostname }}-ceph-restapi - net=host - expose={{ ceph_restapi_port }} - state=running - env="RESTAPI_IP={{ hostvars[inventory_hostname]['ansible_' + ceph_restapi_docker_interface]['ipv4']['address'] }},CEPH_DAEMON=RESTAPI" - volumes="/etc/ceph:/etc/ceph" - -- name: ensure ceph rest api service is running - docker: > - image="{{ ceph_restapi_docker_username }}/{{ ceph_restapi_docker_imagename }}" - name="ceph-{{ ansible_hostname }}" - ports={{ ceph_restapi_port }}:{{ ceph_restapi_port }} - detach=yes - state=running diff --git a/roles/ceph-restapi/tasks/docker/fetch_configs.yml b/roles/ceph-restapi/tasks/docker/fetch_configs.yml new file mode 100644 index 000000000..962ab958e --- /dev/null +++ b/roles/ceph-restapi/tasks/docker/fetch_configs.yml @@ -0,0 +1,26 @@ +--- +- name: set config and keys paths + set_fact: + ceph_config_keys: + - /etc/ceph/ceph.conf + - /etc/ceph/ceph.client.admin.keyring + +- name: stat for ceph config and keys + local_action: stat path={{ item }} + with_items: ceph_config_keys + changed_when: false + sudo: false + ignore_errors: true + register: statconfig + +- name: try to fetch ceph config and keys + copy: > + src=fetch/docker_mon_files/{{ item.0 }} + dest={{ item.0 }} + owner=root + group=root + mode=644 + with_together: + - ceph_config_keys + - statconfig.results + when: item.1.stat.exists == true diff --git a/roles/ceph-restapi/tasks/docker/main.yml b/roles/ceph-restapi/tasks/docker/main.yml new file mode 100644 index 000000000..7210a3f5b --- /dev/null +++ b/roles/ceph-restapi/tasks/docker/main.yml @@ -0,0 +1,4 @@ +--- +- include: pre_requisite.yml +- include: fetch_configs.yml +- include: start_docker_restapi.yml diff --git a/roles/ceph-restapi/tasks/docker/pre_requisite.yml b/roles/ceph-restapi/tasks/docker/pre_requisite.yml new file mode 100644 index 000000000..61ee10124 --- /dev/null +++ b/roles/ceph-restapi/tasks/docker/pre_requisite.yml @@ -0,0 +1,6 @@ +--- +# NOTE (leseb): for version 1.1.0 because https://github.com/ansible/ansible-modules-core/issues/1227 +- name: install docker-py + pip: > + name=docker-py + version=1.1.0 diff --git a/roles/ceph-restapi/tasks/docker/start_docker_restapi.yml b/roles/ceph-restapi/tasks/docker/start_docker_restapi.yml new file mode 100644 index 000000000..8cd470b1e --- /dev/null +++ b/roles/ceph-restapi/tasks/docker/start_docker_restapi.yml @@ -0,0 +1,10 @@ +--- +- name: run the ceph rest api docker image + docker: > + image="{{ ceph_restapi_docker_username }}/{{ ceph_restapi_docker_imagename }}" + name={{ ansible_hostname }}-ceph-restapi + net=host + expose={{ ceph_restapi_port }} + state=running + env="RESTAPI_IP={{ hostvars[inventory_hostname]['ansible_' + ceph_restapi_docker_interface]['ipv4']['address'] }},CEPH_DAEMON=RESTAPI,{{ ceph_restapi_docker_extra_env }}" + volumes="/etc/ceph:/etc/ceph" diff --git a/roles/ceph-restapi/tasks/main.yml b/roles/ceph-restapi/tasks/main.yml index 68ae0ca80..b5d15d694 100644 --- a/roles/ceph-restapi/tasks/main.yml +++ b/roles/ceph-restapi/tasks/main.yml @@ -5,5 +5,5 @@ - include: start_restapi.yml when: not ceph_containerized_deployment -- include: docker.yml +- include: ./docker/main.yml when: ceph_containerized_deployment