
- name: "create {{ systemctl_script_dir }}"
  file:
    path: "{{ systemctl_script_dir }}"
    state: directory
    mode: "0755"

- name: "template or copy script"
  block:
    - name: "render template"
      template:
        src:  "{{ systemctl_script_src }}"
        dest: "{{ [systemctl_script_dir, (systemctl_script_src | basename | regex_replace('\\.j2$', ''))] | path_join }}"
        mode: "0755"
      when: systemctl_script_src.endswith('.j2')

    - name: "copy raw file"
      copy:
        src:  "{{ systemctl_script_src }}"
        dest: "{{ [systemctl_script_dir, (systemctl_script_src | basename)] | path_join }}"
        mode: "0755"
      when: not systemctl_script_src.endswith('.j2')
  when: systemctl_copy_files | bool
