<commit_before>#
# This playbook preps a node for ceph/swift deployment with Ursula
# by unmounting and clearing specified drives in the env's all.yml
#
# Expects a hosts name as input into --extra-vars
#
# ex. ursula envs/example/swift playbooks/test-playbook.yml --extra-vars 'hosts=swiftnode'
#

---
- name: unmount and clear all drives
  hosts: "{{ hosts }}"

  tasks:
  - name: install dependencies
    apt: pkg="gdisk"

  - name: define disk list
    set_fact: disk_list="{{ swift.disks }}"
    when: hosts == "swiftnode"

  - name: define disk list
    set_fact: disk_list="{{ ceph.disks }}"
    when: hosts == "ceph_osds"

  - name: create list of disks present on node
    set_fact:
      disks_present: |
        {% set comma = joiner(",") %}
        [{% for item in hostvars[inventory_hostname]['ansible_devices'] -%}
            {{ comma() }}"{{ item }}"
        {%- endfor %}]

  - name: unmount all mounted devices
    mount: name={{ item.mount }} src={{ item.device }} fstype={{ item.fstype }} state=unmounted
    with_items: "{{ ansible_mounts }}"
    when: (item.mount != "/" or item.mount != "/boot") and "{{ item.device | relpath('/dev') }}" in disk_list

  - name: unmount shared partition if defined
    mount: name={{ item.mount }} src={{ item.device }} fstype={{ item.fstype }} state=unmounted
    with_items: "{{ ansible_mounts }}"
    when: swift.os_shared_partition  is defined and item.device == swift.os_shared_partition and hosts == "swiftnode"

  - name: destroy GPT structures
    shell: sgdisk --zap "/dev/"{{ item }}
    ignore_errors: true
    with_items: disk_list
    when: item in disks_present

  - name: clear all devices
    shell: dd if=/dev/zero of="/dev/"{{ item }} bs=1M count=512
    ignore_errors: true
    with_items: disk_list
    when: item in disks_present
<commit_msg>Allow user to unmount all partitions of a drive declaring just the drive in all.yml rather than the partitions themselves. Also fixed issue where sgdisk would not delete partitions on first pass.<commit_after>#
# This playbook preps a node for ceph/swift deployment with Ursula
# by unmounting and clearing specified drives in the env's all.yml
#
# Expects a hosts name as input into --extra-vars
#
# ex. ursula envs/example/swift playbooks/unmount-and-clear-disks.yml --extra-vars 'hosts=swiftnode'
#

---
- name: unmount and clear all drives
  hosts: "{{ hosts }}"

  tasks:
  - name: install dependencies
    apt: pkg="gdisk"

  - name: define disk list
    set_fact: disk_list="{{ swift.disks }}"
    when: hosts == "swiftnode"

  - name: define disk list
    set_fact: disk_list="{{ ceph.disks }}"
    when: hosts == "ceph_osds"

  - name: create list of disks present on node
    set_fact:
      disks_present: |
        {% set comma = joiner(",") %}
        [{% for item in hostvars[inventory_hostname]['ansible_devices'] -%}
            {{ comma() }}"{{ item }}"
        {%- endfor %}]
  
  - name: unmount all mounted devices
    mount: name={{ item[0].mount }} src={{ item[0].device }} fstype={{ item[0].fstype }} state=unmounted
    with_nested: 
      - "{{ ansible_mounts }}"
      - disk_list
    when: (item[0].mount != "/" and item[0].mount != "/boot") and item[1] in "{{ item[0].device }}"

  - name: unmount shared partition if defined
    mount: name={{ item.mount }} src={{ item.device }} fstype={{ item.fstype }} state=unmounted
    with_items: "{{ ansible_mounts }}"
    when: swift.os_shared_partition is defined and item.device == swift.os_shared_partition and hosts == "swiftnode"

  - name: destroy GPT structures
    shell: sgdisk --zap-all /dev/{{ item }}
    ignore_errors: true
    with_items: disk_list
    when: item in disks_present

  - name: clear all devices
    shell: dd if=/dev/zero of=/dev/{{ item }} bs=1M count=512
    ignore_errors: true
    with_items: disk_list
    when: item in disks_present

{'fraction_non_alphanumeric': 0.1363400725764645, 'fraction_numerical': 0.0038880248833592537, 'mean_word_length': 3.1764069264069263, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6120917', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1230, 'n_words': 383}