Opvolger/ansible/tasks/create-opensuse-partition.yaml
2024-12-01 21:28:16 +01:00

101 lines
3 KiB
YAML

- name: Get OpenSUSE rootfs tar.xz
block:
- name: Creates directory
ansible.builtin.file:
path: "{{ opensuse.target }}"
state: directory
- name: Get stats of OpenSUSE rootfs file
stat:
path: "{{ opensuse.target }}/{{ opensuse.download | basename }}"
register: opensusefile
- name: download rootfs
get_url:
url: "{{ opensuse.download }}"
dest: "{{ opensuse.target }}/{{ opensuse.download | basename }}"
when: not opensusefile.stat.exists
- name: Read device information of {{ target }}
become: true
become_user: root
community.general.parted:
device: "{{ target }}"
unit: MiB
register: disk_info
- name: Print disk_info
ansible.builtin.debug:
var: disk_info
- name: Create new partition for rootfs
block:
- name: Create new partition for rootfs
become: true
become_user: root
community.general.parted:
device: "{{ target }}"
name: rootfs
label: gpt
number: "{{ disk_info.partitions | length + 1 }}"
part_start: "{{ disk_info.partitions[-1].end }}MiB"
part_end: "100%"
state: present
- name: Create a ext4 filesystem on {{ target }}{{ disk_info.partitions | length + 1 }}
become: true
become_user: root
community.general.filesystem:
fstype: ext4
force: true
dev: "{{ target }}{{ disk_info.partitions | length + 1 }}"
uuid: EBD0A0A2-B9E5-4433-87C0-68B6B72699C7
when: not disk_info.partitions[-1].name == 'rootfs'
- name: Creates mount directory
ansible.builtin.file:
path: "{{ opensuse.target }}/mnt"
state: directory
- name: Read device information "{{ target }}"
become: true
become_user: root
community.general.parted:
device: "{{ target }}"
unit: MiB
register: disk_info
- name: Mount "{{ target }}{{ disk_info.partitions[-1].num }}"
become: true
become_user: root
ansible.posix.mount:
path: "{{ opensuse.target }}/mnt"
src: "{{ target }}{{ disk_info.partitions[-1].num }}"
fstype: ext4
state: ephemeral
- name: Get stats of OpenSUSE rootfs file
stat:
path: "{{ opensuse.target }}/mnt/tmp"
register: tmp_in_mount
# - name: Unarchive rootfs to "{{ target }}{{ disk_info.partitions[-1].num }}" (very slow!)
# become: true
# become_user: root
# ansible.builtin.shell: tar -xJvf "{{ opensuse.target }}/{{ opensuse.download | basename }}" --directory "{{ opensuse.target }}/mnt"
# https://github.com/ansible/ansible/issues/38267
- name: Unarchive rootfs to "{{ target }}{{ disk_info.partitions[-1].num }}" (very slow!)
become: true
become_user: root
ansible.builtin.unarchive:
src: "{{ opensuse.target }}/{{ opensuse.download | basename }}"
dest: "{{ opensuse.target }}/mnt"
remote_src: yes
when: not tmp_in_mount.stat.exists
- name: Unmount "{{ opensuse.target }}/mnt" (very slow!)
become: true
become_user: root
ansible.posix.mount:
path: "{{ opensuse.target }}/mnt"
state: unmounted