--- # 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 ansible.builtin.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 ansible.builtin.command: systemd-escape -p --suffix="{{ systemd_mount_suffix }}" "{{ systemd_mount_item }}" changed_when: false register: mount_service_name_escaped when: item.escape_name | default(true) - name: Define mount service name ansible.builtin.set_fact: mount_service_name: "{{ mount_service_name_escaped.stdout | default([systemd_mount_item, systemd_mount_suffix] | join('.')) }}" # NOTE(noonedeadpunk): with s3fs IO error would raise on attempt to change permissions. - name: Create mount target(s) ansible.builtin.file: path: "{{ item.where }}" state: directory owner: "{{ item.owner | default(omit) }}" group: "{{ item.group | default(omit) }}" mode: "0755" failed_when: false when: - item.where is defined - item.state | default('unknown') != 'absent' - item.type != 'swap' tags: - systemd-mount - name: Place mount credentials when required ansible.builtin.copy: dest: "/etc/passwd-{{ mount_service_name }}" content: "{{ item.credentials }}" owner: "root" group: "root" mode: "0600" when: - item.type == "fuse.s3fs" - "'credentials' in item" - name: Create systemd mount services(s) openstack.config_template.config_template: src: "systemd-mount.j2" dest: "/etc/systemd/system/{{ mount_service_name }}" owner: "root" group: "root" mode: "{{ item.unit_mode | default('0644') }}" config_overrides: "{{ item.config_overrides | default({}) }}" config_type: "ini" when: - item.state | default('unknown') != 'absent' - (item.mount_overrides_only is not defined) or (item.mount_overrides_only is defined and not item.mount_overrides_only) tags: - systemd-mount - name: Provision mount overrides file when: - item.mount_overrides_only is defined - item.mount_overrides_only | bool - item.config_overrides | length > 0 tags: - systemd-mount block: - name: Create overrides folder for mount ansible.builtin.file: path: "/etc/systemd/system/{{ mount_service_name }}.d" owner: "root" group: "root" mode: "0755" state: directory - name: Create overrides file openstack.config_template.config_template: dest: "/etc/systemd/system/{{ mount_service_name }}.d/overrides.conf" owner: "root" group: "root" mode: "0644" config_overrides: "{{ item.config_overrides | default({}) }}" config_type: "ini" - name: Load or Unload mount(s) ansible.builtin.systemd: daemon_reload: true name: "{{ mount_service_name }}" 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. If this command fails # the task will be rescued and the regular # systemd module will be attempted before # failing the task run. - name: Set the state of the mount # noqa: command-instead-of-module ansible.builtin.command: "systemctl {{ systemd_mount_states[item.state] }} {{ mount_service_name }}" changed_when: false ignore_errors: true register: set_mount_state_command when: - item.state is defined - name: Set the state of the mount (fallback) ansible.builtin.systemd: name: "{{ mount_service_name }}" state: "{{ item.state }}" when: - set_mount_state_command is failed - name: Unload mount(s) ansible.builtin.systemd: daemon_reload: true name: "{{ mount_service_name }}" enabled: false no_block: true when: - item.state | default('unknown') == 'absent' notify: Remove mount