|
| 1 | +--- |
| 2 | + |
| 3 | +# Configure attached ephemeral devices for storage and swap |
| 4 | + |
| 5 | +- name: Assert that ephemeral_device is defined |
| 6 | + assert: |
| 7 | + that: |
| 8 | + - "ephemeral_device is defined" |
| 9 | + |
| 10 | +- name: Set partition names |
| 11 | + set_fact: |
| 12 | + swap_partition: "{{ ephemeral_device }}1" |
| 13 | + opt_partition: "{{ ephemeral_device }}2" |
| 14 | + |
| 15 | +- name: Ensure ephemeral device is unmounted |
| 16 | + become: yes |
| 17 | + ansible.posix.mount: |
| 18 | + name: "{{ ephemeral_device }}" |
| 19 | + state: "{{ item }}" |
| 20 | + with_items: |
| 21 | + - unmounted |
| 22 | + - absent |
| 23 | + # ^ https://github.com/ansible/ansible/issues/48313 |
| 24 | + |
| 25 | +- name: Get existing partitions |
| 26 | + become: yes |
| 27 | + community.general.parted: |
| 28 | + device: "{{ ephemeral_device }}" |
| 29 | + unit: MiB |
| 30 | + register: ephemeral_partitions |
| 31 | + |
| 32 | +- name: Remove any existing partitions |
| 33 | + become: yes |
| 34 | + community.general.parted: |
| 35 | + device: "{{ ephemeral_device }}" |
| 36 | + number: "{{ item.num }}" |
| 37 | + state: absent |
| 38 | + with_items: |
| 39 | + - "{{ ephemeral_partitions.partitions }}" |
| 40 | + |
| 41 | +- name: Create new disk label |
| 42 | + become: yes |
| 43 | + community.general.parted: |
| 44 | + label: msdos |
| 45 | + device: "{{ ephemeral_device }}" |
| 46 | + |
| 47 | +- name: Create swap partition |
| 48 | + become: yes |
| 49 | + community.general.parted: |
| 50 | + device: "{{ ephemeral_device }}" |
| 51 | + number: 1 |
| 52 | + state: present |
| 53 | + part_start: '0%' |
| 54 | + part_end: "{{ configure_swap_size }}MiB" |
| 55 | + |
| 56 | +- name: Create opt partition |
| 57 | + become: yes |
| 58 | + community.general.parted: |
| 59 | + device: "{{ ephemeral_device }}" |
| 60 | + number: 2 |
| 61 | + state: present |
| 62 | + part_start: "{{ configure_swap_size }}MiB" |
| 63 | + part_end: "100%" |
| 64 | + |
| 65 | +- name: Make swap on partition |
| 66 | + become: yes |
| 67 | + command: "mkswap {{ swap_partition }}" |
| 68 | + |
| 69 | +- name: Write swap to fstab |
| 70 | + become: yes |
| 71 | + ansible.posix.mount: |
| 72 | + path: none |
| 73 | + src: "{{ swap_partition }}" |
| 74 | + fstype: swap |
| 75 | + opts: sw |
| 76 | + passno: 0 |
| 77 | + dump: 0 |
| 78 | + state: present |
| 79 | + |
| 80 | +# XXX: does "parted" plugin ensure the partition is available |
| 81 | +# before moving on? No udev settles here ... |
| 82 | + |
| 83 | +- name: Add all swap |
| 84 | + become: yes |
| 85 | + command: swapon -a |
| 86 | + |
| 87 | +- name: Create /opt filesystem |
| 88 | + become: yes |
| 89 | + community.general.filesystem: |
| 90 | + fstype: ext4 |
| 91 | + # The default ratio is 16384 bytes per inode or so. Reduce that to 8192 |
| 92 | + # bytes per inode so that we get roughly twice the number of inodes as |
| 93 | + # by default. This should still be well above the block size of 4096. |
| 94 | + # We do this because we have found in at least a couple locations that |
| 95 | + # more inodes is useful and is painful to fix after the fact. |
| 96 | + opts: -i 8192 |
| 97 | + dev: "{{ opt_partition }}" |
| 98 | + |
| 99 | +# Rackspace at least does not have enough room for two devstack |
| 100 | +# installs on the primary partition. We copy in the existing /opt to |
| 101 | +# the new partition on the ephemeral device, and then overmount /opt |
| 102 | +# to there for the test runs. |
| 103 | +# |
| 104 | +# NOTE(ianw): the existing "mount" touches fstab. There is currently (Sep2017) |
| 105 | +# work in [1] to split mount & fstab into separate parts, but for now we bundle |
| 106 | +# it into an atomic shell command |
| 107 | +# [1] https://github.com/ansible/ansible/pull/27174 |
| 108 | +- name: Copy old /opt |
| 109 | + become: yes |
| 110 | + register: moving_opt |
| 111 | + shell: | |
| 112 | + mount {{ opt_partition }} /mnt |
| 113 | + find /opt/ -mindepth 1 -maxdepth 1 -print -exec mv {} /mnt/ \; |
| 114 | + umount /mnt |
| 115 | + df -h |
| 116 | + tags: |
| 117 | + - skip_ansible_lint |
| 118 | + |
| 119 | +- name: Output data from old /opt |
| 120 | + debug: |
| 121 | + var: moving_opt |
| 122 | + |
| 123 | +# This overmounts any existing /opt |
| 124 | +- name: Add opt to fstab and mount |
| 125 | + become: yes |
| 126 | + ansible.posix.mount: |
| 127 | + path: /opt |
| 128 | + src: "{{ opt_partition }}" |
| 129 | + fstype: ext4 |
| 130 | + opts: noatime |
| 131 | + state: mounted |
0 commit comments