github.com/jlmeeker/kismatic@v1.10.1-0.20180612190640-57f9005a1f1a/ansible/roles/docker/tasks/direct_lvm.yaml (about)

     1  ---
     2    - name: install lvm2 package
     3      package:
     4        name: lvm2
     5        state: present
     6    - name: create docker volume group
     7      lvg:
     8        pvs: "{{ docker.storage.direct_lvm_block_device.path }}"
     9        state: present
    10        vg: docker
    11    - name: create thinpool logical volume
    12      lvol:
    13        lv: thinpool
    14        vg: docker
    15        size: "{{ docker.storage.direct_lvm_block_device.thinpool_percent }}%VG" # Use 95% of the volume group for this logical volume
    16        opts: --wipesignatures y
    17    
    18    # The following two tasks are used to enable this play to be idempotent. We detect whether
    19    # the logical volume (LV) is already a thin LV using `lvs`, which returns a list
    20    # of all the LVs. `lvs` also displays the LV attributes in the
    21    # lvattr field. According to the `lvs` manpage, the first bit in the attribute list determines
    22    # the LV type. A value of "t" in this bit means "thin pool".
    23    # See `man lvs` for more details.
    24    # Sample output when the "thinpool" LV is of type thin pool:
    25    # > lvs -o lvname,lvattr --no-headings
    26    # thinpool     twi-aot---
    27    - name: list logical volumes
    28      command: lvs -o lvname,lvattr --noheadings
    29      register: logical_volume_list
    30    - name: determine if thin pool conversion is necessary
    31      set_fact:
    32        requires_thin_pool_conversion: True
    33      # Regex: match whitespace, the name of the thin pool, whitespace, and then any character other than 't' or ' '. 
    34      # If the item doesn't match, this means that the "thinpool" LV is already a thin pool, 
    35      # and no conversion is necessary.
    36      when: item | match("\s+thinpool\s+[^t ]+")
    37      with_items: "{{ logical_volume_list.stdout_lines }}"
    38      # ^ TODO: lvs command can output json. Use json when we bump ansible version to 2.2
    39      # when: item.lv_name == "thinpool" and item.lv_attr | match("^t")
    40      # with_items: "{{ logical_volume_list.stdout | json_query('report.lv') }}"
    41    
    42    
    43    # When a thin pool LV is created, two standard LVs are combined into a single thin pool LV.
    44    # The two standard volumes are a data volume and a metadata volume. The resulting combined thin pool takes the name of the 
    45    # data LV (in our case 'thinpool'), and the metadata volume is no longer "listed" as an LV.
    46    # For this reason, we only create the "thinpoolmeta" LV if the thin pool LV has not been created yet.
    47    # If we don't have this check, this would result in an extra LV called "thinpoolmeta" whenever this play 
    48    # is re-run.
    49    # More info can be found in `man lvmthin`
    50    - name: create thinpoolmeta logical volume
    51      lvol:
    52        lv: thinpoolmeta
    53        vg: docker
    54        size: "{{ docker.storage.direct_lvm_block_device.thinpool_metapercent }}%VG" # Use 1% of the volume group for this logical volume
    55        opts: --wipesignatures y
    56      when: requires_thin_pool_conversion is defined and requires_thin_pool_conversion|bool == true
    57    
    58    # This is where we create the thin pool LV, using the docker/thinpool LV
    59    # for storing the data, and the docker/thinpoolmeta LV for the thin pool's metadata
    60    - name: convert the pool to a thin pool
    61      command: lvconvert -y --zero n -c 512K --thinpool docker/thinpool --poolmetadata docker/thinpoolmeta
    62      when: requires_thin_pool_conversion is defined and requires_thin_pool_conversion|bool == true
    63    - name: create auto extension profile
    64      template:
    65        src: docker-thinpool.profile
    66        dest: /etc/lvm/profile/docker-thinpool.profile
    67    - name: apply lvm profile
    68      command: lvchange --metadataprofile docker-thinpool docker/thinpool
    69    - name: enable monitoring to ensure autoextend executes
    70      command: lvchange --metadataprofile docker-thinpool docker/thinpool