项目作者: robertdebock

项目描述 :
Create partitions, volume groups, volumes, filesystems and mounts
高级语言:
项目地址: git://github.com/robertdebock/ansible-role-storage.git
创建时间: 2019-02-26T19:54:39Z
项目社区:https://github.com/robertdebock/ansible-role-storage

开源协议:Apache License 2.0

下载


Ansible role storage

Create partitions, volume groups, volumes, filesystems and mounts

GitHub GitLab Downloads Version
github gitlab downloads Version

Example Playbook

This example is taken from molecule/default/converge.yml and is tested on each push, pull request and release.

  1. ---
  2. - name: Converge
  3. hosts: all
  4. become: true
  5. gather_facts: true
  6. pre_tasks:
  7. # For testing in containers, a loopback device is created in `prepare.yml`.
  8. # The device created in `prepare.yml` is picked up here.
  9. # Normally you would point to /dev/sd*.
  10. - name: Read loop device from disk
  11. ansible.builtin.slurp:
  12. src: /loopback-devicename.txt
  13. register: loopback_devicename
  14. roles:
  15. - role: robertdebock.storage
  16. # Partitioning a loopback device is not supported by parted.
  17. # storage_partitions:
  18. # - name: "{{ loopback_devicename.content | b64decode }}"
  19. # number: 1
  20. # part_end: 100%
  21. # label: gpt
  22. storage_volumegroups:
  23. - name: data
  24. devices:
  25. - "{{ loopback_devicename.content | b64decode }}"
  26. size: 4
  27. storage_volumes:
  28. - name: test1
  29. vg: data
  30. size: 1G
  31. opts: --zero n
  32. storage_filesystems:
  33. - name: /dev/data/test1
  34. fstype: xfs
  35. # Mounting is not idempotent for:
  36. # - debian:bullseye
  37. # - ubuntu:focal
  38. # - ubuntu:bionic
  39. # storage_mounts:
  40. # - name: /mnt/test
  41. # src: /dev/data/test1
  42. # fstype: xfs
  43. # owner: root
  44. # group: root
  45. # mode: "0755"

The machine needs to be prepared. In CI this is done using molecule/default/prepare.yml:

  1. ---
  2. - name: Prepare
  3. hosts: all
  4. become: true
  5. gather_facts: false
  6. roles:
  7. - role: robertdebock.bootstrap
  8. tasks:
  9. # These are "cleanup" tasks, to make sure the test is run in a non-biased environment.
  10. - name: Unmount /mnt/test
  11. ansible.posix.mount:
  12. path: /mnt/test
  13. state: absent
  14. - name: Install lvm2
  15. ansible.builtin.package:
  16. name: lvm2
  17. - name: Remove lv
  18. community.general.lvol:
  19. vg: data
  20. lv: test1
  21. state: absent
  22. force: true
  23. - name: Remove all loop devices
  24. ansible.builtin.command:
  25. cmd: losetup -D
  26. changed_when: true
  27. when:
  28. - ansible_distribution != "Alpine"
  29. - name: Remove loop_device on Alpine
  30. when:
  31. - ansible_distribution == "Alpine"
  32. block:
  33. - name: Find loop devices
  34. ansible.builtin.command:
  35. cmd: losetup -a
  36. register: loop_devices
  37. changed_when: false
  38. - name: Remove loop device
  39. ansible.builtin.command:
  40. cmd: "losetup -d {{ item | split(':') | first }}"
  41. changed_when: true
  42. loop: "{{ loop_devices.stdout_lines }}"
  43. # Since we're in a container, let's create a file.
  44. # Normally you would not require this, as `/dev/sd*` (or so) would be used.
  45. - name: Create a 4GB file
  46. community.general.filesize:
  47. path: /blockdevice.img
  48. size: 4G
  49. owner: root
  50. group: root
  51. mode: "0644"
  52. - name: Find first unused loop device
  53. ansible.builtin.command:
  54. cmd: losetup -f
  55. register: loop_device
  56. changed_when: false
  57. - name: Store loop device on disk
  58. ansible.builtin.copy:
  59. content: "{{ loop_device.stdout }}"
  60. dest: /loopback-devicename.txt
  61. owner: root
  62. group: root
  63. mode: "0644"
  64. - name: Create loop device
  65. ansible.builtin.command:
  66. cmd: losetup {{ loop_device.stdout }} /blockdevice.img
  67. changed_when: true

Also see a full explanation and example on how to use these roles.

Role Variables

The default values for the variables are set in defaults/main.yml:

  1. ---
  2. # defaults file for storage
  3. storage_default_fstype: ext4
  4. # storage_partitions:
  5. # - name: /dev/sdb
  6. # number: 1
  7. # part_end: 4GiB
  8. # label: gpt
  9. # - name: /dev/sdb
  10. # number: 2
  11. # flags:
  12. # - lvm
  13. # part_start: 4GiB
  14. # part_end: 8GiB
  15. # storage_volumegroups:
  16. # - name: group1
  17. # devices:
  18. # - /dev/sdb2
  19. # size: 8
  20. # - name: group2
  21. # devices:
  22. # - /dev/sdb2
  23. # size: 128M
  24. # storage_volumes:
  25. # - name: var1
  26. # vg: group1
  27. # size: 16
  28. # storage_filesystems:
  29. # - name: /dev/group1/var
  30. # fstype: ext4
  31. # storage_mounts:
  32. # - name: /var
  33. # src: /dev/group1/var1
  34. # owner: root
  35. # group: root
  36. # mode: "0755"
  37. # opts: defaults
  38. # boot: true
  39. # dump: 0
  40. # passno: 2

Requirements

State of used roles

The following roles are used to prepare a system. You can prepare your system in another way.

Requirement GitHub GitLab
robertdebock.bootstrap Build Status GitHub Build Status GitLab

Context

This role is a part of many compatible roles. Have a look at the documentation of these roles for further information.

Here is an overview of related roles:
dependencies

Compatibility

This role has been tested on these container images:

container tags
Alpine all
Amazon Candidate
EL 9
Debian all
Fedora all
Ubuntu all

The minimum version of Ansible required is 2.12, tests have been done to:

  • The previous version.
  • The current version.
  • The development version.

If you find issues, please register them in GitHub.

License

Apache-2.0.

Author Information

robertdebock

Please consider sponsoring me.