2016-12-09 20:27:50 +08:00
|
|
|
---
|
|
|
|
|
2016-12-12 21:14:22 +08:00
|
|
|
# Running growpart seems to be only required on Azure, as other Cloud Providers do this at boot time
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Install growpart
|
2017-02-18 05:22:34 +08:00
|
|
|
package:
|
|
|
|
name: cloud-utils-growpart
|
2019-04-18 16:34:08 +08:00
|
|
|
state: present
|
2016-12-09 20:27:50 +08:00
|
|
|
|
2022-01-04 22:48:52 +08:00
|
|
|
- name: Gather mounts facts
|
|
|
|
setup:
|
|
|
|
gather_subset: 'mounts'
|
|
|
|
|
2021-09-28 14:58:42 +08:00
|
|
|
- name: Search root filesystem device
|
|
|
|
vars:
|
|
|
|
query: "[?mount=='/'].device"
|
2023-07-05 11:36:54 +08:00
|
|
|
_root_device: "{{ ansible_mounts | json_query(query) }}"
|
2021-09-28 14:58:42 +08:00
|
|
|
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 }}"
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Check if growpart needs to be run
|
2021-09-28 14:58:42 +08:00
|
|
|
command: growpart -N {{ device }} {{ partition }}
|
2016-12-09 20:27:50 +08:00
|
|
|
failed_when: False
|
|
|
|
changed_when: "'NOCHANGE:' not in growpart_needed.stdout"
|
|
|
|
register: growpart_needed
|
2018-08-05 18:48:07 +08:00
|
|
|
environment:
|
2018-07-31 06:52:56 +08:00
|
|
|
LC_ALL: C
|
2016-12-09 20:27:50 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Check fs type
|
2021-09-28 14:58:42 +08:00
|
|
|
command: file -Ls {{ root_device }}
|
2016-12-09 20:27:50 +08:00
|
|
|
changed_when: False
|
|
|
|
register: fs_type
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Run growpart # noqa no-handler
|
2021-09-28 14:58:42 +08:00
|
|
|
command: growpart {{ device }} {{ partition }}
|
2016-12-09 20:27:50 +08:00
|
|
|
when: growpart_needed.changed
|
2018-08-05 18:48:07 +08:00
|
|
|
environment:
|
2018-07-31 06:56:09 +08:00
|
|
|
LC_ALL: C
|
2016-12-09 20:27:50 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Run xfs_growfs # noqa no-handler
|
2021-09-28 14:58:42 +08:00
|
|
|
command: xfs_growfs {{ root_device }}
|
2018-07-31 06:52:56 +08:00
|
|
|
when: growpart_needed.changed and 'XFS' in fs_type.stdout
|