Determine root filesistem device and partition before running growpart (#8024)

This commit is contained in:
Marcos Lorenzo 2021-09-28 08:58:42 +02:00 committed by GitHub
parent 1472528f6d
commit 4c5328fd1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,8 +7,17 @@
name: cloud-utils-growpart
state: present
- name: Search root filesystem device
vars:
query: "[?mount=='/'].device"
_root_device: "{{ ansible_mounts|json_query(query) }}"
set_fact:
device: "{{ _root_device | first | regex_replace('([^0-9]+)[0-9]+', '\\1') }}"
partition: "{{ _root_device | first | regex_replace('[^0-9]+([0-9]+)', '\\1') }}"
root_device: "{{ _root_device }}"
- name: check if growpart needs to be run
command: growpart -N /dev/sda 1
command: growpart -N {{ device }} {{ partition }}
failed_when: False
changed_when: "'NOCHANGE:' not in growpart_needed.stdout"
register: growpart_needed
@ -16,16 +25,16 @@
LC_ALL: C
- name: check fs type
command: file -Ls /dev/sda1
command: file -Ls {{ root_device }}
changed_when: False
register: fs_type
- name: run growpart # noqa 503
command: growpart /dev/sda 1
command: growpart {{ device }} {{ partition }}
when: growpart_needed.changed
environment:
LC_ALL: C
- name: run xfs_growfs # noqa 503
command: xfs_growfs /dev/sda1
command: xfs_growfs {{ root_device }}
when: growpart_needed.changed and 'XFS' in fs_type.stdout