]> arthur.barton.de Git - AnsibleRoles.git/commitdiff
New "lvm-lv" role
authorAlexander Barton <alex@barton.de>
Mon, 19 Feb 2018 17:10:43 +0000 (18:10 +0100)
committerAlexander Barton <alex@barton.de>
Mon, 19 Feb 2018 17:10:43 +0000 (18:10 +0100)
This role creates an Logical Volume (LV) in an existing LVM Volume
Group (VG), including the ext4 file system. And it even resizes
(enlarges) existing LV and file systems.

The code has been used by the mysql-server role already, but this
patch refactors it into its own reusable "role".

roles/lvm-lv/defaults/main.yml [new file with mode: 0644]
roles/lvm-lv/tasks/main.yml [new file with mode: 0644]
roles/mysql-server/defaults/main.yml
roles/mysql-server/tasks/main.yml

diff --git a/roles/lvm-lv/defaults/main.yml b/roles/lvm-lv/defaults/main.yml
new file mode 100644 (file)
index 0000000..bda9a34
--- /dev/null
@@ -0,0 +1,6 @@
+---
+# lvm-lv defaults
+
+lvm_vg: ""
+lvm_lv_name: ""
+lvm_lv_size: "50g"
diff --git a/roles/lvm-lv/tasks/main.yml b/roles/lvm-lv/tasks/main.yml
new file mode 100644 (file)
index 0000000..5c0f216
--- /dev/null
@@ -0,0 +1,43 @@
+---
+# lvm-lv tasks
+
+# Setup a new LVM volume, create a new ext4 file system, and add it to
+# /etc/fstab and mount it.
+
+- name: setup LVM volume "{{ lvm_lv_name }}" for MySQL
+  tags:
+    - partition
+    - lvm
+    - fs
+  lvol: >
+    lv={{ lvm_lv_name }}
+    size={{ lvm_lv_size }}
+    vg={{ lvm_vg }}
+
+- name: create/resize ext4 filesystem on MySQL partition "{{ lvm_lv_name }}"
+  tags:
+    - fs
+  filesystem: >
+    dev=/dev/{{ lvm_vg }}/{{ lvm_lv_name }}
+    fstype=ext4
+    opts="-L {{ lvm_lv_name }}"
+    resizefs=yes
+
+- name: create mount point "/var/lib/mysql"
+  tags:
+    - fs
+  file: >
+    path=/var/lib/mysql
+    state=directory
+
+- name: configure and mount MySQL partition "{{ lvm_lv_name }}"
+  tags:
+    - fs
+    - mount
+  mount: >
+    fstype=ext4
+    name=/var/lib/mysql
+    src=/dev/{{ lvm_vg }}/{{ lvm_lv_name }}
+    state=mounted
+    opts=rw,errors=remount-ro,noatime
+    passno=2
index e077b4a98368361691b4587bda85ea86308a21eb..cf750a207b6732d8e99ca616ce76d2903e48b802 100644 (file)
@@ -2,6 +2,9 @@
 # mysql-server: defaults
 
 mysql_server_vg: ""
+mysql_server_lv_name: "mysql"
+mysql_server_lv_size: "10g"
+
 mysql_server_ansible_user: "ansible"
 mysql_server_ansible_password: "ansible"
 mysql_server_root_host: "localhost"
index 754920faf5443436a795fdbab5cc3a4867e274d4..6dc9095aab7e78d528fd7fbda76b0c6b8b8a5a6b 100644 (file)
@@ -1,60 +1,17 @@
 ---
 # mysql-server tasks
 
-- name: check if MySQL data already exists
+- name: create LVM LV and file system for MySQL data
   tags:
     - mysql
     - fs
-  command: test -d /var/lib/mysql/mysql
-  ignore_errors: yes
-  check_mode: no
-  register: mysql_server_installed
-  changed_when: false
-
-- name: setup LVM volume "mysql" for MySQL
-  tags:
-    - mysql
-    - partition
-    - lvm
-    - fs
-  lvol: >
-    lv=mysql
-    size=10g
-    vg={{ mysql_server_vg }}
-  when: mysql_server_vg != "" and mysql_server_installed.rc != 0
-
-- name: create ext4 filesystem on MySQL partition "mysql"
-  tags:
-    - mysql
-    - fs
-  filesystem: >
-    dev=/dev/{{ mysql_server_vg }}/mysql
-    fstype=ext4
-    opts="-L mysql"
-  when: mysql_server_vg != "" and mysql_server_installed.rc != 0
-
-- name: create mount point "/var/lib/mysql"
-  tags:
-    - mysql
-    - fs
-  file: >
-    path=/var/lib/mysql
-    state=directory
-  when: mysql_server_vg != "" and mysql_server_installed.rc != 0
-
-- name: configure and mount MySQL partition "mysql"
-  tags:
-    - mysql
-    - fs
-    - mount
-  mount: >
-    fstype=ext4
-    name=/var/lib/mysql
-    src=/dev/{{ mysql_server_vg }}/mysql
-    state=mounted
-    opts=rw,errors=remount-ro,noatime
-    passno=2
-  when: mysql_server_vg != "" and mysql_server_installed.rc != 0
+  include_role:
+    name: lvm-lv
+  vars:
+    lvm_vg: "{{ mysql_server_vg }}"
+    lvm_lv_name: "{{ mysql_server_lv_name }}"
+    lvm_lv_size: "{{ mysql_server_lv_size }}"
+  when: mysql_server_vg != ""
 
 - name: install MySQL packages for client and server
   tags: