131 lines
4.5 KiB
YAML
131 lines
4.5 KiB
YAML
---
|
|
# Copyright 2017, Rackspace US, Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
- name: Check machinectl mount point
|
|
command: mountpoint /var/lib/machines
|
|
failed_when: false
|
|
changed_when: false
|
|
register: machinectl_mount
|
|
|
|
- name: Set the machinectl limit
|
|
shell: |
|
|
machinectl set-limit {{ nspawn_host_machine_volume_size }}
|
|
truncate -s '>{{ nspawn_host_machine_volume_size }}' /var/lib/machines.raw
|
|
changed_when: false
|
|
register: machines_create
|
|
args:
|
|
executable: /bin/bash
|
|
tags:
|
|
- skip_ansible_lint
|
|
|
|
- name: Systemd machinectl mount
|
|
block:
|
|
- name: Format the machines sparse file
|
|
filesystem:
|
|
fstype: btrfs
|
|
dev: /var/lib/machines.raw
|
|
|
|
- name: Create machines mount point
|
|
file:
|
|
path: "/var/lib/machines"
|
|
state: "directory"
|
|
recurse: true
|
|
|
|
- name: Run the systemd service role
|
|
include_role:
|
|
name: systemd_service
|
|
vars:
|
|
systemd_user_name: "root"
|
|
systemd_group_name: "root"
|
|
systemd_tempd_prefix: machine
|
|
systemd_slice_name: machine
|
|
systemd_lock_path: /var/lock/machine
|
|
systemd_CPUAccounting: false
|
|
systemd_BlockIOAccounting: false
|
|
systemd_MemoryAccounting: false
|
|
systemd_TasksAccounting: false
|
|
systemd_services:
|
|
- service_name: "systemd-machined"
|
|
config_overrides:
|
|
Unit:
|
|
Description: "Virtual Machine and Container Registration Service"
|
|
Documentation:
|
|
? "man:systemd-machined.service(8)"
|
|
? "http://www.freedesktop.org/wiki/Software/systemd/machined"
|
|
Wants: "machine.slice"
|
|
After: "machine.slice"
|
|
Service:
|
|
BusName: "org.freedesktop.machine1"
|
|
CapabilityBoundingSet: "CAP_KILL CAP_SYS_PTRACE CAP_SYS_ADMIN CAP_SETGID CAP_SYS_CHROOT CAP_DAC_READ_SEARCH CAP_DAC_OVERRIDE CAP_CHOWN CAP_FOWNER CAP_FSETID"
|
|
WatchdogSec: "3min"
|
|
execstarts:
|
|
- "/lib/systemd/systemd-machined"
|
|
enabled: yes
|
|
state: started
|
|
tags:
|
|
- machines-config
|
|
- systemd-service
|
|
|
|
- name: Run the systemd mount role
|
|
include_role:
|
|
name: systemd_mount
|
|
vars:
|
|
systemd_mounts:
|
|
- what: "/var/lib/machines.raw"
|
|
where: "/var/lib/machines"
|
|
options: "loop,defaults,noatime,nodiratime,compress=lzo,commit=120,{{ (ansible_kernel is version('4.5', '>=')) | ternary('space_cache=v2', 'space_cache') }}"
|
|
type: "btrfs"
|
|
state: 'started'
|
|
enabled: true
|
|
tags:
|
|
- systemd-mount
|
|
- machines-config
|
|
when:
|
|
- machinectl_mount.rc != 0
|
|
|
|
- meta: flush_handlers
|
|
|
|
- name: Update quota system and group limits
|
|
block:
|
|
- name: Disable|Enable the machinectl quota system
|
|
command: "btrfs quota {{ nspawn_host_machine_quota_disabled | bool | ternary('disable', 'enable') }} /var/lib/machines"
|
|
changed_when: false
|
|
|
|
- name: Set the qgroup size|compression limits on machines
|
|
command: "btrfs qgroup limit {{ item }} /var/lib/machines"
|
|
changed_when: false
|
|
with_items:
|
|
- "-e {{ nspawn_host_qgroup_space_limit }}"
|
|
- "-c {{ nspawn_host_qgroup_compression_limit }}"
|
|
when:
|
|
- not nspawn_host_machine_quota_disabled | bool
|
|
rescue:
|
|
- name: Notice regarding quota system
|
|
debug:
|
|
msg: >-
|
|
The machinectl quota system could not be setup. Check the system to
|
|
for qutoa system availability otherwise disable it by setting
|
|
`nspawn_host_machine_quota_disabled` to true.
|
|
|
|
# NOTE(cloudnull): Because the machines mount may be a manually created sparse
|
|
# file we run an online resize to ensure the machines mount is
|
|
# the size we expect.
|
|
- name: Ensure the machines fs is sized correctly
|
|
command: "btrfs filesystem resize max /var/lib/machines"
|
|
changed_when: false
|
|
failed_when: false
|
|
when:
|
|
- machines_create is changed
|