From 9fd14cb6ea081eb3e561446c724f7606d4e2c2cb Mon Sep 17 00:00:00 2001
From: Alexander Block <ablock84@gmail.com>
Date: Fri, 9 Dec 2016 13:27:50 +0100
Subject: [PATCH] Add growpart role to allow growing the root partition on
 CentOS

At least the OS images from Azure do not grow the root FS automatically.
---
 .../preinstall/tasks/growpart-centos-7.yml    | 23 +++++++++++++++++++
 roles/kubernetes/preinstall/tasks/main.yml    |  6 +++++
 2 files changed, 29 insertions(+)
 create mode 100644 roles/kubernetes/preinstall/tasks/growpart-centos-7.yml

diff --git a/roles/kubernetes/preinstall/tasks/growpart-centos-7.yml b/roles/kubernetes/preinstall/tasks/growpart-centos-7.yml
new file mode 100644
index 000000000..506589760
--- /dev/null
+++ b/roles/kubernetes/preinstall/tasks/growpart-centos-7.yml
@@ -0,0 +1,23 @@
+---
+
+- name: install growpart
+  package: name=cloud-utils-growpart state=latest
+
+- name: check if growpart needs to be run
+  command: growpart -N /dev/sda 1
+  failed_when: False
+  changed_when: "'NOCHANGE:' not in growpart_needed.stdout"
+  register: growpart_needed
+
+- name: check fs type
+  command: file -Ls /dev/sda1
+  changed_when: False
+  register: fs_type
+
+- name: run growpart
+  command: growpart /dev/sda 1
+  when: growpart_needed.changed
+
+- name: run xfs_growfs
+  command: xfs_growfs /dev/sda1
+  when: growpart_needed.changed and 'XFS' in fs_type.stdout
\ No newline at end of file
diff --git a/roles/kubernetes/preinstall/tasks/main.yml b/roles/kubernetes/preinstall/tasks/main.yml
index fd8a808a3..5f2662339 100644
--- a/roles/kubernetes/preinstall/tasks/main.yml
+++ b/roles/kubernetes/preinstall/tasks/main.yml
@@ -180,3 +180,9 @@
 
 - include: resolvconf.yml
   tags: [bootstrap-os, resolvconf]
+  
+- include: growpart-centos-7.yml
+  when: ansible_distribution in ["CentOS","RedHat"] and
+        ansible_distribution_major_version >= 7
+  tags: bootstrap-os
+
-- 
GitLab