--- - name: Curl and execute scripts on target machine hosts: target_hosts become: yes # Use sudo if needed tasks: - name: Create temporary directory for scripts file: path: /tmp/downloaded_scripts state: directory mode: '0755' - name: Download scripts from remote sources get_url: url: "{{ item.url }}" dest: "/tmp/downloaded_scripts/{{ item.name }}" mode: '0755' # Make executable loop: - { name: 'script1.sh', url: 'https://example.com/scripts/script1.sh' } - { name: 'script2.sh', url: 'https://example.com/scripts/script2.sh' } register: downloaded_scripts - name: Execute downloaded scripts shell: "/tmp/downloaded_scripts/{{ item.item.name }}" loop: "{{ downloaded_scripts.results }}" register: script_output - name: Display script execution results debug: msg: "{{ item.stdout_lines }}" loop: "{{ script_output.results }}" - name: Clean up temporary directory file: path: /tmp/downloaded_scripts state: absent when: cleanup_after | default(true)