Commit 7ef61c50 authored by Oyvind.Gjesdal's avatar Oyvind.Gjesdal
Browse files

#2, laget volumes option for rolle

parent b76b4ec2
......@@ -10,6 +10,7 @@ A small role for generic system tasks common for UB
* (Optional) adds environment variables
* (Optional) adds [IUS](https://ius.io/) default 'false' repo for centos7
* (Optional) adds chronic for system email and sets email in /var/spool/cron jobs
* (Optional) adds volumes (Already created and attached, not using )
Requirements
------------
Requires centos 7
......@@ -39,6 +40,11 @@ Example Playbook
environments:
- { name: "ENV", value: "VALUE" }
- { name: "ENV2, value: "VALUE" }
volumes:
- mount_point: /data
device: /dev/sdb
- mount_point: /media
device: /dev/sdc
```
License
-------
......
---
# defaults file for centos7-system
#hostname:
volumes: []
rebootOnChange_minute: 01
rebootOnChange_hour: 01
system_user: centos
......
......@@ -4,6 +4,11 @@
fail: msg="Operating System {{ ansible_distribution }}-{{ ansible_distribution_version }} not supported, use centos|redhat 7"
when: (ansible_distribution|lower != "centos" and ansible_distribution|lower !=redhat) or ansible_distribution_major_version != "7"
- name: "import volume.yml"
import_tasks: volume.yml
when: "volumes | length > 0"
become: true
- name: "cron job for yum update and rebooting on kernel changes"
cron:
name: "reboot on change needed"
......@@ -78,4 +83,3 @@
path: "/etc/hosts"
become: true
when: "hostname is defined"
- name: "Installing lvm2"
yum:
name: "lvm2"
state: "present"
- name: "Update volumes to volumes add, with default values for vgname,lvname and fs_type (ext4) if not set"
set_fact:
volumes_add: "{{ volumes_add | default([]) + [{'device' : item.device
, 'vgname': item.vgname| default(item.mount_point | regex_replace('^.*/([^/]+$)','vg_\\1'))
, 'lvname': item.lvname| default(item.mount_point | regex_replace('^.*/([^/]+$)','lv_\\1'))
, 'mount_point': item.mount_point
, 'fs_type': item.fs_type| default('ext4')}] }}"
with_items: "{{ volumes }}"
- name: "Create new volume groups"
lvg:
vg: "{{ item.vgname }}"
pvs: "{{ item.device }}"
state: "present"
with_items: "{{ volumes_add }}"
- name: "Creating new logical volumes"
lvol:
vg: "{{ item.vgname }}"
lv: "{{ item.lvname }}"
size: "100%FREE"
shrink: "no"
with_items: "{{ volumes_add }}"
- name: "Creating new filesystems on new volumes"
filesystem:
fstype: "{{ item.fs_type }}"
dev: "/dev/{{ item.vgname }}/{{ item.lvname }}"
with_items: "{{ volumes_add }}"
- name: "Create mount points"
file:
path: "{{ item.mount_point }}"
state: "directory"
mode: 0755
with_items: "{{ volumes_add }}"
- name: "Mounting new filesystems"
mount:
name: "{{ item.mount_point }}"
src: "/dev/{{ item.vgname }}/{{ item.lvname }}"
fstype: "{{ item.fs_type }}"
state: "mounted"
with_items: "{{ volumes_add }}"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment