- name: Start App Service service: name: myappservice state: started delegate_to: localhost run_once: true ignore_errors: yes register: result - name: Fail if app service failed to start fail: msg: "Failed to start app service" when: result['failed'] == true
- name: Copy file to remote server copy: src: /path/to/local/file dest: /path/to/remote/file delegate_to: "{{ target }}" run_once: true register: result - name: Fail if copy failed fail: msg: "Failed to copy file to remote server" when: result['failed'] == trueIn this example, we're using the `copy` module to copy a file from a local path to a remote server. We're delegating the task to a variable named `target` and running it once. We're also registering the result of the task in the `result` variable. Next, we're checking if the task failed by looking at the `failed` property of the `result`. If it's true, we're using the `fail` module to raise an exception with a message that the copy failed. Package library: ansible.errors