Browse Source

Merge pull request #1521 from mwoodson/docker_lvm

role: added docker_storage_setup
Matt Woodson 9 years ago
parent
commit
fadad1f7e1

+ 0 - 39
roles/docker_storage/README.md

@@ -1,39 +0,0 @@
-docker_storage
-=========
-
-Configure docker_storage options
-------------
-
-None
-
-Role Variables
---------------
-
-None
-
-Dependencies
-------------
-
-None
-
-Example Playbook
-----------------
-
-Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
-
-    - hosts: servers
-      roles:
-         - { role/docker_storage: 
-               - key: df.fs
-                 value: xfs
-         }
-
-License
--------
-
-ASL 2.0
-
-Author Information
-------------------
-
-OpenShift operations, Red Hat, Inc

+ 0 - 1
roles/docker_storage/defaults/main.yml

@@ -1 +0,0 @@
----

+ 0 - 1
roles/docker_storage/handlers/main.yml

@@ -1 +0,0 @@
----

+ 0 - 9
roles/docker_storage/meta/main.yml

@@ -1,9 +0,0 @@
----
-galaxy_info:
-  author: OpenShift
-  description:  Setup docker_storage options
-  company: Red Hat, Inc
-  license: ASL 2.0
-  min_ansible_version: 1.2
-dependencies:
-- docker

+ 0 - 37
roles/docker_storage/tasks/main.yml

@@ -1,37 +0,0 @@
----
-- lvg:
-    pvs: "{{ dst_device }}"
-    vg: "{{ dst_vg }}"
-  register: dst_lvg
-
-- lvol:
-    lv: data
-    vg: "{{ dst_vg }}"
-    size: 95%VG
-  register: dst_lvol_data
-
-- lvol:
-    lv: metadata
-    vg: "{{ dst_vg }}"
-    size: 5%VG
-  register: dst_lvol_metadata
-  
-
-- name: Update docker_storage options
-  lineinfile:
-    dest: /etc/sysconfig/docker-storage
-    backrefs: yes
-    regexp: "^(DOCKER_STORAGE_OPTIONS=)"
-    line: '\1 --storage-opt {{ dst_options | oo_combine_key_value("=") | join(" --storage-opt ") }}'
-  when: dst_options is defined and dst_options | length > 0
-  register: dst_config
-
-
-- name: Reload systemd units
-  command: systemctl daemon-reload
-  notify:
-  - restart docker
-  when: dst_config | changed or 
-        dst_lvg | changed or
-        dst_lvol_data | changed or
-        dst_lvol_metadata | changed

+ 0 - 1
roles/docker_storage/vars/main.yml

@@ -1 +0,0 @@
----

+ 42 - 0
roles/docker_storage_setup/README.md

@@ -0,0 +1,42 @@
+docker_storage_setup
+=========
+This role coverts docker to go from loopback to direct-lvm (the Red Hat recommended way to run docker).
+
+It requires the block device to be already provisioned and attached to the host.
+
+  Notes:
+  * This is NOT idempotent. Conversion needs to be done for it to be idempotent
+  * This will remove /var/lib/docker!
+  * You will need to re-deploy docker images
+
+Configure docker_storage_setup
+------------
+
+None
+
+Role Variables
+--------------
+
+dss_docker_device: defaults to /dev/xvdb
+
+Dependencies
+------------
+
+None
+
+Example Playbook
+----------------
+
+    - hosts: servers
+      roles:
+         - { role/docker_storage_setup, dss_docker_device: '/dev/xvdb' }
+
+License
+-------
+
+ASL 2.0
+
+Author Information
+------------------
+
+OpenShift operations, Red Hat, Inc

+ 2 - 0
roles/docker_storage_setup/defaults/main.yml

@@ -0,0 +1,2 @@
+---
+dss_docker_device: /dev/xvdb

+ 95 - 0
roles/docker_storage_setup/tasks/main.yml

@@ -0,0 +1,95 @@
+---
+- name: Ensure docker is installed
+  action: "{{ ansible_pkg_mgr }} name={{ item }} state=present"
+  with_items:
+  - docker
+
+# Docker doesn't seem to start cleanly the first time run
+#  when loopback (not directlvm) is configured. Putting in an
+#  ignore errors, and then sleeping till it can come up cleanly
+- name: Try to start docker.  This might fail (loopback startup issue)
+  service:
+    name: docker
+    state: started
+  ignore_errors: yes
+
+- name: Pause for 1 minute
+  pause:
+    seconds: 30
+
+- name: Ensure docker is started
+  service:
+    name: docker
+    state: started
+
+- name: Determine if loopback
+  shell: docker info | grep 'Data file:.*loop'
+  register: loop_device_check
+  ignore_errors: yes
+
+- debug:
+    var: loop_device_check
+
+- name: fail if we don't detect loopback
+  fail:
+    msg:  loopback not detected! Please investigate manually.
+  when: loop_device_check.rc == 1
+
+- name: "check to see if {{ dss_docker_device }} exists"
+  command: "test -e {{ dss_docker_device }}"
+  register: docker_dev_check
+  ignore_errors: yes
+
+- debug: var=docker_dev_check
+
+- name: "fail if {{ dss_docker_device }} doesn't exist"
+  fail:
+    msg: "{{ dss_docker_device }} doesn't exist. Please investigate"
+  when: docker_dev_check.rc != 0
+
+- name: stop docker
+  service:
+    name: docker
+    state: stopped
+
+- name: delete /var/lib/docker
+  command: rm -rf /var/lib/docker
+
+- name: remove /var/lib/docker
+  command: rm -rf /var/lib/docker
+
+- name: copy the docker-storage-setup config file
+  copy:
+    content: >
+      DEVS={{ dss_docker_device }}\n
+      VG=docker_vg
+    dest: /etc/sysconfig/docker-storage-setup
+    owner: root
+    group: root
+    mode: 0664
+
+- name: docker storage setup
+  command: docker-storage-setup
+  register: docker_storage_setup_output
+
+- debug:
+    msg:  "{{ docker_storage_setup_output }}"
+
+- name: extend the vg
+  command: lvextend -l 90%VG /dev/docker_vg/docker-pool
+  register: lvextend_output
+
+- debug:
+    msg: "{{ lvextend_output }}"
+
+- name: start docker
+  service:
+    name: docker
+    state: restarted
+
+- name: docker info
+  command: docker info
+  register: dockerinfo
+
+- debug:
+    msg: "{{ dockerinfo }}"