d1dc867ef1
The mount role was using the systemd module to start / stop mounts however if a mount was restarted when it could have been reloaded the role could create a fair amount of chaos in a running environment. This change maps the mount states appropriately to the systemctl command options to ensure we're not needlessly restarting mounts should the unit files change. The `systemd_mount_states` has been added which will map the normal Ansible states to suitable systemd mount states and the mount state is being managed using the `systemctl` command instead of the ansible module. Change-Id: I5c7e5105e54d3ff9ad040f2a1d003d3dd12e4efb Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
91 lines
2.8 KiB
YAML
91 lines
2.8 KiB
YAML
---
|
|
# Copyright 2018, 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: Set mount facts
|
|
set_fact:
|
|
systemd_mount_suffix: "{{ (item.type == 'swap') | ternary('swap', 'mount') }}"
|
|
systemd_mount_item: "{{ item.where | default(item.what) }}"
|
|
|
|
- name: Escape mount service file name
|
|
command: systemd-escape -p --suffix="{{ systemd_mount_suffix }}" "{{ systemd_mount_item }}"
|
|
changed_when: false
|
|
register: mount_service_name
|
|
|
|
- name: Create mount target(s)
|
|
file:
|
|
path: "{{ item.where }}"
|
|
state: directory
|
|
owner: "{{ item.owner | default(omit) }}"
|
|
group: "{{ item.group | default(omit) }}"
|
|
mode: "0755"
|
|
when:
|
|
- item.where is defined
|
|
- item.state | default('unknown') != 'absent'
|
|
- item.type != 'swap'
|
|
tags:
|
|
- systemd-mount
|
|
|
|
- name: Create systemd mount services(s)
|
|
config_template:
|
|
src: "systemd-mount.j2"
|
|
dest: "/etc/systemd/system/{{ mount_service_name.stdout }}"
|
|
owner: "root"
|
|
group: "root"
|
|
mode: "0640"
|
|
config_overrides: "{{ item.config_overrides | default({}) }}"
|
|
config_type: "ini"
|
|
when:
|
|
- item.state | default('unknown') != 'absent'
|
|
tags:
|
|
- systemd-mount
|
|
|
|
- name: Load or Unload mount(s)
|
|
systemd:
|
|
daemon_reload: yes
|
|
name: "{{ mount_service_name.stdout }}"
|
|
enabled: "{{ item.enabled | default(true) }}"
|
|
when:
|
|
- item.state | default('unknown') != 'absent'
|
|
|
|
# NOTE(cloudnull): The systemd module is not used to start the
|
|
# mount because we don't want to inavertently
|
|
# "restart" a mount unnecessarily. To ensure
|
|
# we're able to load new options without
|
|
# requiring a mount restart the systemctl
|
|
# command is used with the "reload-or-restart"
|
|
# argument. Additionally this command escapes
|
|
# the name of the mount.
|
|
- name: Set the state of the mount
|
|
shell: >-
|
|
systemctl
|
|
{{ systemd_mount_states[item.state] }}
|
|
$(systemd-escape -p --suffix="{{ systemd_mount_suffix }}" "{{ systemd_mount_item }}")
|
|
args:
|
|
warn: no
|
|
when:
|
|
- item.state is defined
|
|
tags:
|
|
- skip_ansible_lint
|
|
|
|
- name: Unload mount(s)
|
|
systemd:
|
|
daemon_reload: yes
|
|
name: "{{ mount_service_name.stdout }}"
|
|
enabled: false
|
|
no_block: yes
|
|
when:
|
|
- item.state | default('unknown') == 'absent'
|
|
notify: Remove mount
|