diff options
| author | Jenkins <jenkins@review.openstack.org> | 2015-11-23 22:42:48 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2015-11-23 22:42:48 +0000 |
| commit | 6f648105fe6971fc50f4a73387a3f97fa310708f (patch) | |
| tree | 581a4725e4dabc6f52c012c7ea514dcc3d5d5031 /ansible | |
| parent | d3efbd07dc4d6095089666011dc79ac3bcae8036 (diff) | |
| parent | dd16395ae1fe7e1005f99b875c578f931dc624c7 (diff) | |
| download | kolla-6f648105fe6971fc50f4a73387a3f97fa310708f.tar.gz kolla-6f648105fe6971fc50f4a73387a3f97fa310708f.zip | |
Merge "Switch find_disks to use a decent python lib"
Diffstat (limited to 'ansible')
| -rw-r--r-- | ansible/library/find_disks.py | 88 | ||||
| -rw-r--r-- | ansible/roles/ceph/meta/main.yml | 3 | ||||
| -rw-r--r-- | ansible/roles/ceph/tasks/bootstrap_osds.yml | 48 | ||||
| -rw-r--r-- | ansible/roles/ceph/tasks/start_osds.yml | 32 | ||||
| -rwxr-xr-x | ansible/roles/common/tasks/start.yml | 2 |
5 files changed, 52 insertions, 121 deletions
diff --git a/ansible/library/find_disks.py b/ansible/library/find_disks.py deleted file mode 100644 index d7f166fc9..000000000 --- a/ansible/library/find_disks.py +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/python - -# Copyright 2015 Sam Yaple -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This module has been relicensed from the source below: -# https://github.com/SamYaple/yaodu/blob/master/ansible/library/ceph_osd_list - -DOCUMENTATION = ''' ---- -module: find_disks -short_description: Return list of devices containing a specfied label -description: - - This will return a list of all devices with a GPT partition label with - the name specified. -options: - partition_name: - description: - - Partition name - required: True - type: bool -author: Sam Yaple -''' - -EXAMPLES = ''' -- hosts: ceph-osd - tasks: - - name: Return all valid formated devices with the name KOLLA_CEPH_OSD - ceph_osd_list: - partition_name: 'KOLLA_CEPH_OSD' - register: osds -''' - -import sys -import subprocess - - -def main(): - module = AnsibleModule( - argument_spec = dict( - partition_name = dict(required=True, type='str') - ) - ) - - partition_name = module.params.get('partition_name') - - try: - # This should all really be done differently. Unfortunately there is no - # decent python library for dealing with disks like we need to here. - disks = subprocess.check_output("parted -l", shell=True).split('\n') - ret = list() - - for line in disks: - d = line.split(' ') - if d[0] == 'Disk' and d[1] != 'Flags:': - dev = d[1][:-1] - - if line.find(partition_name) != -1: - # This process returns an error code when no results return - # We can ignore that, it is safe - p = subprocess.Popen("blkid " + dev + "*", shell=True, stdout=subprocess.PIPE) - blkid_out = p.communicate()[0] - # The dev doesn't need to have a uuid, will be '' otherwise - if ' UUID=' in blkid_out: - fs_uuid = blkid_out.split(' UUID="')[1].split('"')[0] - else: - fs_uuid = '' - ret.append({'device': dev, 'fs_uuid': fs_uuid}) - - module.exit_json(disks=ret) - except Exception as e: - module.exit_json(failed=True, msg=repr(e)) - -# import module snippets -from ansible.module_utils.basic import * -if __name__ == '__main__': - main() diff --git a/ansible/roles/ceph/meta/main.yml b/ansible/roles/ceph/meta/main.yml new file mode 100644 index 000000000..6b4fff8fe --- /dev/null +++ b/ansible/roles/ceph/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - { role: common } diff --git a/ansible/roles/ceph/tasks/bootstrap_osds.yml b/ansible/roles/ceph/tasks/bootstrap_osds.yml index 39802d080..8a0158d7d 100644 --- a/ansible/roles/ceph/tasks/bootstrap_osds.yml +++ b/ansible/roles/ceph/tasks/bootstrap_osds.yml @@ -1,15 +1,27 @@ --- - name: Looking up disks to bootstrap for Ceph - find_disks: - partition_name: 'KOLLA_CEPH_OSD_BOOTSTRAP' - register: osds_bootstrap - when: inventory_hostname in groups['ceph-osd'] + command: docker exec -t kolla_ansible /usr/bin/ansible localhost + -m find_disks + -a "partition_name='KOLLA_CEPH_OSD_BOOTSTRAP'" + register: osd_lookup + changed_when: "{{ osd_lookup.stdout.find('localhost | SUCCESS => ') != -1 and (osd_lookup.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" + failed_when: osd_lookup.stdout.split()[2] != 'SUCCESS' -- name: Looking up disks to bootstrap for Ceph cache - find_disks: - partition_name: 'KOLLA_CEPH_OSD_CACHE_BOOTSTRAP' - register: osds_cache_bootstrap - when: inventory_hostname in groups['ceph-osd'] +- name: Reading data from variable + set_fact: + osds_bootstrap: "{{ (osd_lookup.stdout.split('localhost | SUCCESS => ')[1]|from_json).disks|from_json }}" + +- name: Looking up disks to bootstrap for Ceph + command: docker exec -t kolla_ansible /usr/bin/ansible localhost + -m find_disks + -a "partition_name='KOLLA_CEPH_OSD_CACHE_BOOTSTRAP'" + register: osd_cache_lookup + changed_when: "{{ osd_cache_lookup.stdout.find('localhost | SUCCESS => ') != -1 and (osd_cache_lookup.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" + failed_when: osd_cache_lookup.stdout.split()[2] != 'SUCCESS' + +- name: Reading data from variable + set_fact: + osds_cache_bootstrap: "{{ (osd_cache_lookup.stdout.split('localhost | SUCCESS => ')[1]|from_json).disks|from_json }}" - name: Bootstrapping Ceph OSDs docker: @@ -33,8 +45,7 @@ KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" OSD_DEV: "{{ item.1.device }}" OSD_INITIAL_WEIGHT: "{{ osd_initial_weight }}" - with_indexed_items: osds_bootstrap['disks']|default([]) - when: inventory_hostname in groups['ceph-osd'] + with_indexed_items: osds_bootstrap|default([]) # https://github.com/ansible/ansible-modules-core/pull/1031 - name: Waiting for bootstrap containers to exit @@ -42,8 +53,7 @@ register: bootstrap_result run_once: True failed_when: bootstrap_result.stdout != "0" - with_indexed_items: osds_bootstrap['disks']|default([]) - when: inventory_hostname in groups['ceph-osd'] + with_indexed_items: osds_bootstrap|default([]) - name: Cleaning up bootstrap containers docker: @@ -51,8 +61,7 @@ name: "bootstrap_osd_{{ item.0 }}" image: "{{ ceph_osd_image_full }}" state: absent - with_indexed_items: osds_bootstrap['disks']|default([]) - when: inventory_hostname in groups['ceph-osd'] + with_indexed_items: osds_bootstrap|default([]) - name: Bootstrapping Ceph Cache OSDs docker: @@ -77,8 +86,7 @@ CEPH_CACHE: OSD_DEV: "{{ item.1.device }}" OSD_INITIAL_WEIGHT: "{{ osd_initial_weight }}" - with_indexed_items: osds_cache_bootstrap['disks']|default([]) - when: inventory_hostname in groups['ceph-osd'] + with_indexed_items: osds_cache_bootstrap|default([]) # https://github.com/ansible/ansible-modules-core/pull/1031 - name: Waiting for bootstrap containers to exit @@ -86,8 +94,7 @@ register: bootstrap_result run_once: True failed_when: bootstrap_result.stdout != "0" - with_indexed_items: osds_cache_bootstrap['disks']|default([]) - when: inventory_hostname in groups['ceph-osd'] + with_indexed_items: osds_cache_bootstrap|default([]) - name: Cleaning up bootstrap containers docker: @@ -95,5 +102,4 @@ name: "bootstrap_osd_cache_{{ item.0 }}" image: "{{ ceph_osd_image_full }}" state: absent - with_indexed_items: osds_cache_bootstrap['disks']|default([]) - when: inventory_hostname in groups['ceph-osd'] + with_indexed_items: osds_cache_bootstrap|default([]) diff --git a/ansible/roles/ceph/tasks/start_osds.yml b/ansible/roles/ceph/tasks/start_osds.yml index 657f9483a..ab7bd35dd 100644 --- a/ansible/roles/ceph/tasks/start_osds.yml +++ b/ansible/roles/ceph/tasks/start_osds.yml @@ -1,20 +1,27 @@ --- - name: Looking up OSDs for Ceph - find_disks: - partition_name: 'KOLLA_CEPH_DATA' - register: osds + command: docker exec -t kolla_ansible /usr/bin/ansible localhost + -m find_disks + -a "partition_name='KOLLA_CEPH_DATA'" + register: osd_lookup + changed_when: "{{ osd_lookup.stdout.find('localhost | SUCCESS => ') != -1 and (osd_lookup.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" + failed_when: osd_lookup.stdout.split()[2] != 'SUCCESS' + +- name: Reading data from variable + set_fact: + osds: "{{ (osd_lookup.stdout.split('localhost | SUCCESS => ')[1]|from_json).disks|from_json }}" - name: Mounting Ceph OSD volumes mount: src: "UUID={{ item.fs_uuid }}" fstype: xfs state: mounted - name: "/var/lib/ceph/osd/{{ item.fs_uuid }}" - with_items: osds.disks + name: "/var/lib/ceph/osd/{{ item['fs_uuid'] }}" + with_items: osds - name: Gathering OSD IDs - command: 'cat /var/lib/ceph/osd/{{ item.fs_uuid }}/whoami' - with_items: osds.disks + command: "cat /var/lib/ceph/osd/{{ item['fs_uuid'] }}/whoami" + with_items: osds register: id changed_when: False failed_when: id.rc != 0 @@ -36,15 +43,16 @@ name: "ceph_osd_{{ item.0.stdout }}" image: "{{ ceph_osd_image_full }}" volumes: - - "/var/lib/ceph/osd/{{ item.1.fs_uuid }}:/var/lib/ceph/osd/ceph-{{ item.0.stdout }}" + - "/var/lib/ceph/osd/{{ item.1['fs_uuid'] }}:/var/lib/ceph/osd/ceph-{{ item.0.stdout }}" - "{{ node_config_directory }}/ceph-osd/:{{ container_config_directory }}/:ro" - "/dev/:/dev/" env: KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" OSD_ID: "{{ item.0.stdout }}" - OSD_DEV: "{{ item.1.device }}" + OSD_DEV: "{{ item.1['device'] }}" with_together: - id.results - - osds.disks - when: inventory_hostname in groups['ceph-osd'] - and osds.disks + - osds + when: + - inventory_hostname in groups['ceph-osd'] + - osds diff --git a/ansible/roles/common/tasks/start.yml b/ansible/roles/common/tasks/start.yml index 2484c896b..68ba56be0 100755 --- a/ansible/roles/common/tasks/start.yml +++ b/ansible/roles/common/tasks/start.yml @@ -60,4 +60,6 @@ ANSIBLE_LIBRARY: "/usr/share/ansible" volumes: - /var/lib/kolla/dev/log:/dev/log + - /dev/:/dev/ + - /run/:/run/ command: "/bin/sleep infinity" |
