From 5e05db87e0788e99a46bfb170f11e1ce8a8dcd1e Mon Sep 17 00:00:00 2001 From: Matt Woodson Date: Mon, 29 Feb 2016 12:14:47 -0500 Subject: role: added docker_storage_setup --- roles/docker_storage/tasks/main.yml | 4 +- roles/docker_storage_setup/README.md | 42 ++++++++++++++ roles/docker_storage_setup/defaults/main.yml | 2 + roles/docker_storage_setup/tasks/main.yml | 82 ++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 roles/docker_storage_setup/README.md create mode 100644 roles/docker_storage_setup/defaults/main.yml create mode 100755 roles/docker_storage_setup/tasks/main.yml diff --git a/roles/docker_storage/tasks/main.yml b/roles/docker_storage/tasks/main.yml index 48a3fc208..71467d8a8 100644 --- a/roles/docker_storage/tasks/main.yml +++ b/roles/docker_storage/tasks/main.yml @@ -15,7 +15,7 @@ vg: "{{ dst_vg }}" size: 5%VG register: dst_lvol_metadata - + - name: Update docker_storage options lineinfile: @@ -31,7 +31,7 @@ command: systemctl daemon-reload notify: - restart docker - when: dst_config | changed or + when: dst_config | changed or dst_lvg | changed or dst_lvol_data | changed or dst_lvol_metadata | changed diff --git a/roles/docker_storage_setup/README.md b/roles/docker_storage_setup/README.md new file mode 100644 index 000000000..6039b349a --- /dev/null +++ b/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 diff --git a/roles/docker_storage_setup/defaults/main.yml b/roles/docker_storage_setup/defaults/main.yml new file mode 100644 index 000000000..5013aba97 --- /dev/null +++ b/roles/docker_storage_setup/defaults/main.yml @@ -0,0 +1,2 @@ +--- +dss_docker_device: /dev/xvdb diff --git a/roles/docker_storage_setup/tasks/main.yml b/roles/docker_storage_setup/tasks/main.yml new file mode 100755 index 000000000..1a30ea4cb --- /dev/null +++ b/roles/docker_storage_setup/tasks/main.yml @@ -0,0 +1,82 @@ +--- +- name: Ensure docker is installed + action: "{{ ansible_pkg_mgr }} name={{ item }} state=present" + with_items: + - docker + +- name: start docker + 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 }}" -- cgit v1.2.3 From 8c060c8c612d465a5314e5ac4c57053185351c9e Mon Sep 17 00:00:00 2001 From: Matt Woodson Date: Mon, 29 Feb 2016 12:18:39 -0500 Subject: role_removal: docker_storage; This is the old way, no longer used --- roles/docker_storage/README.md | 39 ---------------------------------- roles/docker_storage/defaults/main.yml | 1 - roles/docker_storage/handlers/main.yml | 1 - roles/docker_storage/meta/main.yml | 9 -------- roles/docker_storage/tasks/main.yml | 37 -------------------------------- roles/docker_storage/vars/main.yml | 1 - 6 files changed, 88 deletions(-) delete mode 100644 roles/docker_storage/README.md delete mode 100644 roles/docker_storage/defaults/main.yml delete mode 100644 roles/docker_storage/handlers/main.yml delete mode 100644 roles/docker_storage/meta/main.yml delete mode 100644 roles/docker_storage/tasks/main.yml delete mode 100644 roles/docker_storage/vars/main.yml diff --git a/roles/docker_storage/README.md b/roles/docker_storage/README.md deleted file mode 100644 index bf0158623..000000000 --- a/roles/docker_storage/README.md +++ /dev/null @@ -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 diff --git a/roles/docker_storage/defaults/main.yml b/roles/docker_storage/defaults/main.yml deleted file mode 100644 index ed97d539c..000000000 --- a/roles/docker_storage/defaults/main.yml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/roles/docker_storage/handlers/main.yml b/roles/docker_storage/handlers/main.yml deleted file mode 100644 index ed97d539c..000000000 --- a/roles/docker_storage/handlers/main.yml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/roles/docker_storage/meta/main.yml b/roles/docker_storage/meta/main.yml deleted file mode 100644 index f5b2d53cb..000000000 --- a/roles/docker_storage/meta/main.yml +++ /dev/null @@ -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 diff --git a/roles/docker_storage/tasks/main.yml b/roles/docker_storage/tasks/main.yml deleted file mode 100644 index 71467d8a8..000000000 --- a/roles/docker_storage/tasks/main.yml +++ /dev/null @@ -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 diff --git a/roles/docker_storage/vars/main.yml b/roles/docker_storage/vars/main.yml deleted file mode 100644 index ed97d539c..000000000 --- a/roles/docker_storage/vars/main.yml +++ /dev/null @@ -1 +0,0 @@ ---- -- cgit v1.2.3 From fb6729d41ff81c19dd79709ad77aaac11df6c711 Mon Sep 17 00:00:00 2001 From: Matt Woodson Date: Mon, 29 Feb 2016 14:42:18 -0500 Subject: added extra steps to ensure docker starts up --- roles/docker_storage_setup/tasks/main.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/roles/docker_storage_setup/tasks/main.yml b/roles/docker_storage_setup/tasks/main.yml index 1a30ea4cb..8af9bbe1e 100755 --- a/roles/docker_storage_setup/tasks/main.yml +++ b/roles/docker_storage_setup/tasks/main.yml @@ -4,7 +4,20 @@ with_items: - docker -- name: start 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 -- cgit v1.2.3