Skip to content

Copying service files not placed correctly on node #84

@asiebens

Description

@asiebens

Hi,

I've been implementing the collection in my playbooks but I've encountered a problem when using the systemd role.

Context

Folder structure:

├─ files/
│   ├─ podman/
│   │   └─ file1.container
│   ├─ selinux/
│   │   └─ file2.cil
│   └─ systemd/
│       └─ file3.service
└─ playbook.yml

Playbook:

- name: Set up container
  hosts: all
  vars:
    podman_run_as_user: <me>
    podman_run_as_group: <me>
    podman_activate_systemd_unit: false
    podman_quadlet_specs:
      - file_src: files/podman/file1.container
    selinux_modules:
      - path: files/selinux/file2.cil
        state: enabled
    systemd_unit_files:
      - item: files/systemd/file3.service
        user: <me>
        state: present
    systemd_started_units:
      - item: file3.service
        user: <me>
  roles:
    - fedora.linux_system_roles.selinux
    - fedora.linux_system_roles.systemd
    - fedora.linux_system_roles.podman

Problem

When running the playbook, it failes on the step Ensure unit files are present:

- name: Ensure unit files are present
copy:
src: "{{ item.item }}"
dest: "{{ __path }}/{{ __file }}"
owner: "{{ item.user }}"
group: "{{ item.group }}"
mode: "{{ item.mode }}"
when: __systemd_list_name == "systemd_unit_files"
loop: "{{ __systemd_present }}"
register: __systemd_unit_files_result

It appends the local, relative, path (files/systemd/file3.service) to the base path on the node (~/.config/systemd/user/), but this results in a failure as it tries to place this file in ~/.config/systemd/user/files/systemd/file3.service with the intermediate folders not existing of course.

__file only strips the .j2 extension in case of template files but nothing gets done in case of normal files.

Expected result

I expected the role to strip the folders from item so that while the source is still the same as provided, dest only appends the filename instead of the full local path.

I took a look at the podman role as this issue does not occur there in the following task: https://github.com/linux-system-roles/podman/blob/4063a6b347531ecc32c68b31e092443e5074c456/tasks/create_update_quadlet_spec.yml#L56-L64

- name: Ensure quadlet file is copied
  copy:
    src: "{{ __podman_quadlet_file_src }}"
    dest: "{{ __podman_quadlet_file }}"
    owner: "{{ __podman_user }}"
    group: "{{ __podman_group }}"
    mode: "0644"
  register: __podman_copy_file
  when: __podman_quadlet_file_src | length > 0

Here src is equal to __podman_quadlet_file_src, which is a var set in https://github.com/linux-system-roles/podman/blob/4063a6b347531ecc32c68b31e092443e5074c456/tasks/handle_quadlet_spec.yml#L28-L30

    __podman_quadlet_file_src: "{{ __podman_quadlet_spec_item['file_src']
      if 'file_src' in __podman_quadlet_spec_item
      else none }}"

dest is equal to __podman_quadlet_file which is set by https://github.com/linux-system-roles/podman/blob/4063a6b347531ecc32c68b31e092443e5074c456/tasks/handle_quadlet_spec.yml#L157-L161

    __podman_quadlet_file: "{{ __file if __file and __file is abs
      else __podman_quadlet_path ~ '/' ~ __file
      if __file
      else __podman_quadlet_path ~ '/' ~ __podman_quadlet_name ~
      '.' ~ __podman_quadlet_type }}"

The result of which is that file1.container is placed in ~/.config/containers/systemd/file1.container even though the local path is files/podman/file1.container.

Request

Would we be able to implement a similar solution as I'm not a fan of putting files intended for copying to nodes in the root of the project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions