--- - name: Glob all files in role directory ansible.builtin.find: paths: "{{ role_path }}" depth: 1 file_type: file register: scripts_files - name: "Ensure script directory exist" ansible.builtin.file: path: "{{ ansible_facts.env.HOME }}/.local/bin" state: directory mode: "0755" - name: "Deploy scripts (local with symlinks)" ansible.builtin.file: src: "{{ item.path }}" dest: "{{ ansible_facts.env.HOME }}/.local/bin/{{ item.path | basename }}" state: link force: true loop: "{{ scripts_files.files }}" when: ansible_connection == 'local' - name: "Deploy scripts (remote with copy)" ansible.builtin.copy: src: "{{ item.path }}" dest: "{{ ansible_facts.env.HOME }}/.local/bin/{{ item.path | basename }}" mode: '0755' loop: "{{ scripts_files.files }}" when: ansible_connection != 'local'