-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added rhev-1tb-ssd.yml to the tools dir
This playbook Is for creating /vm partition where the RHEV virtual machines will reside And also for creating a 50G swap partition Signed-off-by: Adam Kraitman <[email protected]>
- Loading branch information
Showing
1 changed file
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
--- | ||
### This playbook is useful for setting up a baremetal hosts (irvingi or senta) | ||
### as a RHEL Hypervisor to serve Jenkins VMs. Expects a RHEL7 image | ||
### already subscribed to RHSM and had ceph-cm-ansible common role | ||
### ran against it. | ||
|
||
- hosts: | ||
- irvingi | ||
# - senta | ||
vars: | ||
# Default to configure /vms disk | ||
configure_disk: true | ||
swap_volume: /dev/sdb1 | ||
swap_disk: /dev/sdb | ||
swappiness: 1 | ||
vars_prompt: | ||
# Forcefully reconfigure disk even if it's already mounted | ||
- name: "force_configure_disk" | ||
prompt: "\nWARNING: You will lose data if you enter \"y\"\nDo you want to forcefully reconfigure the VMs disk even if it's already set up? (y|n)" | ||
default: "n" | ||
become: true | ||
tasks: | ||
|
||
- name: Enable rhev-mgmt repo | ||
command: "subscription-manager repos --enable=rhel-7-server-rhev-mgmt-agent-rpms" | ||
|
||
- name: Install packages | ||
yum: | ||
name: "{{ item }}" | ||
state: latest | ||
enablerepo: epel | ||
with_items: | ||
- gdisk | ||
- parted | ||
- vdsm | ||
|
||
- name: Find 1TB SSD | ||
set_fact: | ||
vm_ssd: "{{ item.key }}" | ||
with_dict: "{{ ansible_devices }}" | ||
when: item.value.model == "Samsung SSD 850" | ||
|
||
# This is where the RHEV virtual machines will reside | ||
- name: Make /vms dir and set permissions | ||
file: | ||
state: directory | ||
path: /vms | ||
owner: vdsm | ||
group: kvm | ||
|
||
# Unmount /vms so configure_disk is set to true | ||
- name: Unmount 1TB SSD if we're forcefully reconfiguring | ||
mount: | ||
name: /vms | ||
state: unmounted | ||
when: force_configure_disk == "y" | ||
|
||
- name: Update ansible_mounts | ||
setup: | ||
filter: ansible_mounts | ||
when: force_configure_disk == "y" | ||
|
||
# Check if the 1TB SSD is already mounted at the /vms mountpoint. | ||
# This is the ONLY way the playbook checks if the host is already configured | ||
- name: Check if /vms already mounted | ||
set_fact: | ||
configure_disk: false | ||
with_items: "{{ ansible_mounts }}" | ||
when: '"/vms" in item.mount' | ||
|
||
- debug: var=configure_disk | ||
|
||
- name: Zap 1TB SSD | ||
command: sgdisk -Z "/dev/{{ vm_ssd }}" | ||
when: configure_disk == true | ||
|
||
- name: Create partition table | ||
command: "parted -s /dev/{{ vm_ssd }} mktable msdos" | ||
when: configure_disk == true | ||
|
||
- name: Create partition | ||
command: "parted /dev/{{ vm_ssd }} unit '%' mkpart primary 0 100" | ||
when: configure_disk == true | ||
|
||
- name: Create filesystem | ||
filesystem: | ||
fstype: xfs | ||
dev: "/dev/{{ vm_ssd }}1" | ||
force: yes | ||
when: configure_disk == true | ||
|
||
- name: Find VM partition UUID | ||
command: "lsblk -n -o uuid /dev/{{ vm_ssd }}1" | ||
register: vm_uuid | ||
|
||
- name: Mount 1TB SSD to /vms | ||
mount: | ||
name: /vms | ||
src: "UUID={{ vm_uuid.stdout }}" | ||
fstype: xfs | ||
opts: defaults | ||
state: mounted | ||
|
||
- name: Copy RHEV SSH key to root's authorized_keys | ||
authorized_key: | ||
user: root | ||
key: http://mgr01.front.sepia.ceph.com/engine.ssh.key.txt | ||
|
||
- name: check that sdb exist | ||
set_fact: | ||
sdb_disk: "{{ ansible_devices.keys() | select('match','sdb') | map('regex_replace','^','dev/') | list }}" | ||
tags: | ||
- create.swap | ||
|
||
- name: Check if a swap partition exist | ||
shell: cat /proc/swaps | tail -1 | ||
register: swap_exist | ||
check_mode: no | ||
tags: | ||
- create.swap | ||
|
||
- name: Run multipath -v3 | ||
shell: multipath -v3 | ||
when: | ||
- swap_exist.stdout.find('dev') == -1 | ||
- sdb_disk[0].find('dev/sdb') != -1 | ||
tags: | ||
- create.swap | ||
|
||
- name: Create a new primary partition on /dev/sdb | ||
parted: | ||
device: /dev/sdb | ||
part_type: primary | ||
number: 1 | ||
state: present | ||
when: | ||
- swap_exist.stdout.find('dev') == -1 | ||
- sdb_disk[0].find('dev/sdb') != -1 | ||
tags: | ||
- create.swap | ||
|
||
- name: Create swap partition | ||
command: mkswap -L swap1 {{swap_volume}} | ||
when: | ||
- swap_exist.stdout.find('dev') == -1 | ||
- sdb_disk[0].find('dev/sdb') != -1 | ||
tags: | ||
- create.swap | ||
|
||
- name: Write swap entry in fstab | ||
mount: name=none | ||
src={{swap_volume}} | ||
fstype=swap | ||
opts=sw | ||
passno=0 | ||
dump=0 | ||
state=present | ||
when: | ||
- swap_exist.stdout.find('dev') == -1 | ||
- sdb_disk[0].find('dev/sdb') != -1 | ||
tags: | ||
- create.swap | ||
|
||
- name: Turn on swap | ||
command: swapon -a | ||
when: | ||
- swap_exist.stdout.find('dev') == -1 | ||
- sdb_disk[0].find('dev/sdb') != -1 | ||
tags: | ||
- create.swap | ||
|
||
- name: Restart mulltipath service | ||
systemd: | ||
state: restarted | ||
name: multipathd.service | ||
when: | ||
- swap_exist.stdout.find('dev') == -1 | ||
- sdb_disk[0].find('dev/sdb') != -1 | ||
tags: | ||
- create.swap | ||
|
||
- name: Set swappiness | ||
sysctl: | ||
name: vm.swappiness | ||
value: "{{swappiness}}" | ||
when: | ||
- swap_exist.stdout.find('dev') == -1 | ||
- sdb_disk[0].find('dev/sdb') != -1 | ||
tags: | ||
- create.swap |