- name: Deploy RemoteSysManager script
  hosts: all
  become: yes

  vars:
    script_url: "http://your_script_url/webctl"
    script_path: "/usr/local/bin/webctl"
    systemd_service_name: "webctl.service"
    systemd_service_path: "/etc/systemd/system/{{ systemd_service_name }}"

  tasks:
    - name: Download webctl script
      ansible.builtin.get_url:
        url: "{{ script_url }}"
        dest: "{{ script_path }}"
        mode: '0755'

    - name: Create systemd service file for webctl
      ansible.builtin.copy:
        dest: "{{ systemd_service_path }}"
        content: |
          [Unit]
          Description=RemoteSysManager Service
          After=network.target

          [Service]
          Type=simple
          ExecStart={{ script_path }}
          Restart=on-failure

          [Install]
          WantedBy=multi-user.target
        mode: '0644'

    - name: Reload systemd daemon
      ansible.builtin.systemd:
        daemon_reload: yes

    - name: Enable and start webctl service
      ansible.builtin.systemd:
        name: "{{ systemd_service_name }}"
        enabled: yes
        state: started
