Add linux.storage.loopback statetags/mcp0.5
multipath: | multipath: | ||||
enabled: false | enabled: false | ||||
Linux with local loopback device | |||||
.. code-block:: yaml | |||||
linux: | |||||
storage: | |||||
loopback: | |||||
disk1: | |||||
file: /srv/disk1 | |||||
size: 50G | |||||
External config generation | External config generation | ||||
-------------------------- | -------------------------- | ||||
[Unit] | |||||
Description=Setup {{ device_name }} device | |||||
DefaultDependencies=no | |||||
After=systemd-udev-settle.service | |||||
Before=lvm2-activation-early.service | |||||
Wants=systemd-udev-settle.service | |||||
[Service] | |||||
{# The command is prefixed with '-' to consider it a success if the loopback device is already setup #} | |||||
ExecStart=-/sbin/losetup {{ device_name }} {{ file }} | |||||
Type=oneshot | |||||
[Install] | |||||
WantedBy=local-fs.target |
description "Setup {{ device_name }} device" | |||||
start on filesystem | |||||
task | |||||
pre-start script | |||||
if /sbin/losetup {{ device_name }}; then | |||||
stop ; exit 0 | |||||
fi | |||||
end script | |||||
exec losetup {{ device_name }} {{ file }} |
'mount': {}, | 'mount': {}, | ||||
'swap': {}, | 'swap': {}, | ||||
'lvm': {}, | 'lvm': {}, | ||||
'loopback': {}, | |||||
'multipath': { | 'multipath': { | ||||
'enabled': False, | 'enabled': False, | ||||
'pkgs': ['multipath-tools', 'multipath-tools-boot'], | 'pkgs': ['multipath-tools', 'multipath-tools-boot'], | ||||
'mount': {}, | 'mount': {}, | ||||
'swap': {}, | 'swap': {}, | ||||
'lvm': {}, | 'lvm': {}, | ||||
'loopback': {}, | |||||
'multipath': { | 'multipath': { | ||||
'enabled': False, | 'enabled': False, | ||||
'pkgs': ['multipath-tools', 'multipath-tools-boot'], | 'pkgs': ['multipath-tools', 'multipath-tools-boot'], | ||||
'mount': {}, | 'mount': {}, | ||||
'swap': {}, | 'swap': {}, | ||||
'lvm': {}, | 'lvm': {}, | ||||
'loopback': {}, | |||||
'multipath': { | 'multipath': { | ||||
'enabled': False, | 'enabled': False, | ||||
'pkgs': [], | 'pkgs': [], |
{%- from "linux/map.jinja" import storage with context %} | {%- from "linux/map.jinja" import storage with context %} | ||||
{%- if storage.mount|length > 0 or storage.swap|length > 0 or storage.multipath.enabled or storage.lvm|length > 0 %} | |||||
{%- if storage.mount|length > 0 or storage.swap|length > 0 or storage.multipath.enabled or storage.lvm|length > 0 or storage.loopback|length > 0 %} | |||||
include: | include: | ||||
{%- if storage.loopback|length > 0 %} | |||||
- linux.storage.loopback | |||||
{%- endif %} | |||||
{%- if storage.mount|length > 0 %} | {%- if storage.mount|length > 0 %} | ||||
- linux.storage.mount | - linux.storage.mount | ||||
{%- endif %} | {%- endif %} |
{%- from "linux/map.jinja" import storage with context %} | |||||
{%- if storage.get('enabled', False) %} | |||||
{%- for device, loopback in storage.loopback|dictsort %} | |||||
{%- if loopback.get('enabled', True) %} | |||||
{{ salt['file.dirname'](loopback.file) }}: | |||||
file.directory: | |||||
- makedirs: true | |||||
- require_in: | |||||
- file: {{ loopback.file }} | |||||
{{ loopback.file }}: | |||||
cmd.run: | |||||
- name: "truncate --size {{ loopback.size|default('1G') }} {{ loopback.file }}" | |||||
- creates: {{ loopback.file }} | |||||
loopback_{{ device }}_init_script: | |||||
file.managed: | |||||
{%- if grains.get('init', None) == 'upstart' %} | |||||
- name: /etc/init/setup-loopback-{{ device }}.conf | |||||
- source: salt://linux/files/setup-loopback-device.upstart | |||||
{%- else %} | |||||
- name: /etc/systemd/system/setup-loopback-{{ device }}.service | |||||
- source: salt://linux/files/setup-loopback-device.systemd | |||||
{%- endif %} | |||||
- template: jinja | |||||
- defaults: | |||||
file: {{ loopback.file }} | |||||
device_name: "/dev/loop{{ loop.index0 }}" | |||||
setup-loopback-{{ device }}: | |||||
service.running: | |||||
- enable: true | |||||
- require: | |||||
- cmd: {{ loopback.file }} | |||||
- file: loopback_{{ device }}_init_script | |||||
{%- endif %} | |||||
{%- endfor %} | |||||
{%- endif %} |