Bug 1971395

Summary: even though a successfully playbook run, the job result is still marked as failed
Product: Red Hat Satellite Reporter: matt jia <mjia>
Component: Ansible - Configuration ManagementAssignee: Hao Chang Yu <hyu>
Status: CLOSED ERRATA QA Contact: Danny Synk <dsynk>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.9.0CC: ahumbe, aruzicka, hyu, mmccune, oezr, osousa, spurrier
Target Milestone: 6.10.0Keywords: Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: tfm-rubygem-foreman_ansible_core-4.1.1 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-11-16 14:11:39 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
tfm-rubygem-foreman_ansible_core-3.0.4.1-2.HFRHBZ1971395.el7sat.noarch.rpm none

Description matt jia 2021-06-14 01:29:20 UTC
When using a playbook with blocks to handle errors, it's run successfully but the job is marked as failed.

Playbook:
~~~
- hosts: all
  gather_facts: false
  tasks:
     - name: Handle the error
       block:
         - name: Print a message
           ansible.builtin.debug:
             msg: 'I execute normally'
    
         - name: Force a failure
           ansible.builtin.command: /bin/false
           ignore_errors: yes
    
         - name: Never print this
           ansible.builtin.debug:
             msg: 'I never execute, due to the above task failing, :-('
       rescue:
         - name: Print when errors
           ansible.builtin.debug:
             msg: 'I caught an error, can do stuff here to fix it, :-)'
~~~

Comment 4 Bryan Kearney 2021-06-30 00:01:21 UTC
Moving this bug to POST for triage into Satellite since the upstream issue https://projects.theforeman.org/issues/32796 has been resolved.

Comment 5 Adam Ruzicka 2021-07-14 06:41:14 UTC
Only tfm-rubygem-foreman_ansible-6.3.1 is needed for 6.10 and it is already released. Changing flags.

We shuffled the code around a bit, for Sat 7.0+ the code will live in smart_proxy_ansible.

Comment 6 Danny Synk 2021-07-16 16:16:21 UTC
Failed QA on Satellite 6.10, snap 9 (tfm-rubygem-foreman_ansible-6.3.1-1.el7sat.noarch).

Steps to test:

1. Register a host to Satellite and configure it for remote execution.
2. Using the "Ansible Playbook" job category and the "Ansible - Run playbook" job template, execute the following playbook on the host:

~~~
- hosts: all
  gather_facts: false
  tasks:
    - name: Handle the error
      block:
        - name: Print a message
          ansible.builtin.debug:
            msg: 'I execute normally'
    
        - name: Force a failure
          command: /bin/false
    
        - name: Never print this
          ansible.builtin.debug:
            msg: 'I never execute, due to the above task failing, :-('
      rescue:
        - name: Print when errors
          ansible.builtin.debug:
            msg: 'I caught an error, can do stuff here to fix it, :-)'
~~~

Expected Result:
When the rescue section is triggered, the playbook run returns an exit status of 0 and the job task is marked as successful by Satellite.

Actual Results:
When the rescue section is triggered, the playbook run returns an exit status of 2, although no failed tasks are reported:

~~~
---
proxy_output:
  result:
  - output_type: stdout
    output: "[WARNING]: Callback disabled by environment. Disabling the Foreman callback\r\nplugin.\n"
    timestamp: 1626449833.380423
  - output_type: stdout
    output: "\n"
    timestamp: 1626449833.3805053
  - output_type: stdout
    output: "\r\nPLAY [all] *********************************************************************\n"
    timestamp: 1626449833.3805819
  - output_type: stdout
    output: "\r\nTASK [Print a message] *********************************************************\n"
    timestamp: 1626449833.3806827
  - output_type: stdout
    output: "\n"
    timestamp: 1626449833.3807538
  - output_type: stdout
    output: "ok: [host.example.com] => {\r\n    \"msg\": \"I execute
      normally\"\r\n}\n"
    timestamp: 1626449833.3808503
  - output_type: stdout
    output: "\r\nTASK [Force a failure] *********************************************************\n"
    timestamp: 1626449833.3809142
  - output_type: stdout
    output: "\n"
    timestamp: 1626449833.380987
  - output_type: stdout
    output: 'fatal: [host.example.com]: FAILED! => {"ansible_facts":
      {"discovered_interpreter_python": "/usr/bin/python"}, "changed": true, "cmd":
      ["/bin/false"], "delta": "0:00:00.003264", "end": "2021-07-16 11:37:15.395710",
      "msg": "non-zero return code", "rc": 1, "start": "2021-07-16 11:37:15.392446",
      "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}

'
    timestamp: 1626449836.5889127
  - output_type: stdout
    output: "\r\nTASK [Print when errors] *******************************************************\n"
    timestamp: 1626449836.5890079
  - output_type: stdout
    output: "\n"
    timestamp: 1626449836.589068
  - output_type: stdout
    output: "ok: [host.example.com] => {\r\n    \"msg\": \"I caught
      an error, can do stuff here to fix it, :-)\"\r\n}\n"
    timestamp: 1626449836.5891511
  - output_type: stdout
    output: |-
      PLAY RECAP *********************************************************************
      host.example.com : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=1    ignored=0
    timestamp: 1626449836.5893147
  exit_status: 2
~~~ 


In the Dynflow console entry for the job, the Actions::ProxyAction subtask of the Actions::RemoteExecution::RunHostJob is marked as successful. However, the Actions::RemoteExecution::RunHostJob task shows a result of "error" with the error message "Job execution failed" and the following traceback:


~~~
---
- "/opt/theforeman/tfm/root/usr/share/gems/gems/algebrick-0.7.3/lib/algebrick/matchers/abstract.rb:74:in
  `block in assigns'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/algebrick-0.7.3/lib/algebrick/matchers/abstract.rb:73:in
  `tap'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/algebrick-0.7.3/lib/algebrick/matchers/abstract.rb:73:in
  `assigns'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/algebrick-0.7.3/lib/algebrick/matching.rb:56:in
  `match_value'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/algebrick-0.7.3/lib/algebrick/matching.rb:36:in
  `block in match?'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/algebrick-0.7.3/lib/algebrick/matching.rb:35:in
  `each'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/algebrick-0.7.3/lib/algebrick/matching.rb:35:in
  `match?'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/algebrick-0.7.3/lib/algebrick/matching.rb:23:in
  `match'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/execution_plan/steps/error.rb:13:in
  `new'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/action.rb:501:in
  `set_error'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/action.rb:464:in
  `error!'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_remote_execution-4.5.1/app/lib/actions/remote_execution/run_host_job.rb:98:in
  `check_exit_status'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_remote_execution-4.5.1/app/lib/actions/remote_execution/run_host_job.rb:69:in
  `finalize'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/action.rb:593:in
  `block (2 levels) in execute_finalize'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:27:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:19:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:40:in
  `finalize'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:23:in
  `call'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:27:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:19:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-4.1.2/app/lib/actions/middleware/rails_executor_wrap.rb:20:in
  `block in finalize'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/execution_wrapper.rb:88:in
  `wrap'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-4.1.2/app/lib/actions/middleware/rails_executor_wrap.rb:19:in
  `finalize'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:23:in
  `call'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:27:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:19:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/action/progress.rb:31:in
  `with_progress_calculation'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/action/progress.rb:23:in
  `finalize'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:23:in
  `call'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:27:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:19:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-4.1.2/app/lib/actions/middleware/load_setting_values.rb:25:in
  `finalize'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:23:in
  `call'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:27:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:19:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-4.1.2/app/lib/actions/middleware/keep_current_request_id.rb:19:in
  `block in finalize'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-4.1.2/app/lib/actions/middleware/keep_current_request_id.rb:52:in
  `restore_current_request_id'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-4.1.2/app/lib/actions/middleware/keep_current_request_id.rb:19:in
  `finalize'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:23:in
  `call'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:27:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:19:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-4.1.2/app/lib/actions/middleware/keep_current_timezone.rb:19:in
  `block in finalize'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-4.1.2/app/lib/actions/middleware/keep_current_timezone.rb:44:in
  `restore_curent_timezone'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-4.1.2/app/lib/actions/middleware/keep_current_timezone.rb:19:in
  `finalize'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:23:in
  `call'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:27:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:19:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-4.1.2/app/lib/actions/middleware/keep_current_user.rb:25:in
  `block in finalize'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-4.1.2/app/lib/actions/middleware/keep_current_user.rb:54:in
  `restore_curent_user'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-4.1.2/app/lib/actions/middleware/keep_current_user.rb:25:in
  `finalize'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:23:in
  `call'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:27:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:19:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-4.1.2/app/lib/actions/middleware/keep_current_taxonomies.rb:19:in
  `block in finalize'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-4.1.2/app/lib/actions/middleware/keep_current_taxonomies.rb:45:in
  `restore_current_taxonomies'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-4.1.2/app/lib/actions/middleware/keep_current_taxonomies.rb:19:in
  `finalize'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:23:in
  `call'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/world.rb:31:in
  `execute'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/action.rb:592:in
  `block in execute_finalize'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/action.rb:472:in
  `block in with_error_handling'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/action.rb:472:in
  `catch'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/action.rb:472:in
  `with_error_handling'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/action.rb:591:in
  `execute_finalize'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/action.rb:285:in
  `execute'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/execution_plan/steps/abstract_flow_step.rb:18:in
  `block (2 levels) in execute'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/execution_plan/steps/abstract.rb:167:in
  `with_meta_calculation'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/execution_plan/steps/abstract_flow_step.rb:17:in
  `block in execute'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/execution_plan/steps/abstract_flow_step.rb:32:in
  `open_action'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/execution_plan/steps/abstract_flow_step.rb:16:in
  `execute'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/director/sequential_manager.rb:78:in
  `run_step'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/director/sequential_manager.rb:63:in
  `dispatch'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/director/sequential_manager.rb:70:in
  `block in run_in_sequence'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/director/sequential_manager.rb:70:in
  `all?'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/director/sequential_manager.rb:70:in
  `run_in_sequence'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/director/sequential_manager.rb:59:in
  `dispatch'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/director/sequential_manager.rb:28:in
  `block in finalize'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:27:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:19:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:48:in
  `finalize_phase'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:23:in
  `call'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:27:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:19:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:48:in
  `finalize_phase'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:23:in
  `call'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:27:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:19:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:48:in
  `finalize_phase'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:23:in
  `call'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:27:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:19:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:48:in
  `finalize_phase'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:23:in
  `call'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:27:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:19:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:48:in
  `finalize_phase'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:23:in
  `call'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:27:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:19:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:48:in
  `finalize_phase'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:23:in
  `call'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:27:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:19:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-4.1.2/app/lib/actions/middleware/keep_current_user.rb:29:in
  `block in finalize_phase'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-4.1.2/app/lib/actions/middleware/keep_current_user.rb:54:in
  `restore_curent_user'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/foreman-tasks-4.1.2/app/lib/actions/middleware/keep_current_user.rb:29:in
  `finalize_phase'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:23:in
  `call'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:27:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:19:in
  `pass'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware.rb:48:in
  `finalize_phase'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/stack.rb:23:in
  `call'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/middleware/world.rb:31:in
  `execute'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/director/sequential_manager.rb:27:in
  `finalize'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/director.rb:122:in
  `execute'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/executors/sidekiq/worker_jobs.rb:11:in
  `block (2 levels) in perform'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/executors.rb:18:in
  `run_user_code'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/executors/sidekiq/worker_jobs.rb:9:in
  `block in perform'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/executors/sidekiq/worker_jobs.rb:25:in
  `with_telemetry'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/executors/sidekiq/worker_jobs.rb:8:in
  `perform'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/dynflow-1.4.8/lib/dynflow/executors/sidekiq/serialization.rb:27:in
  `perform'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:192:in
  `execute_job'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:165:in
  `block (2 levels) in process'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/middleware/chain.rb:128:in
  `block in invoke'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/middleware/chain.rb:133:in
  `invoke'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:164:in
  `block in process'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:137:in
  `block (6 levels) in dispatch'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/job_retry.rb:109:in
  `local'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:136:in
  `block (5 levels) in dispatch'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq.rb:37:in
  `block in <module:Sidekiq>'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:132:in
  `block (4 levels) in dispatch'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:250:in
  `stats'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:127:in
  `block (3 levels) in dispatch'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/job_logger.rb:8:in
  `call'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:126:in
  `block (2 levels) in dispatch'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/job_retry.rb:74:in
  `global'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:125:in
  `block in dispatch'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/logging.rb:48:in
  `with_context'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/logging.rb:42:in
  `with_job_hash_context'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:124:in
  `dispatch'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:163:in
  `process'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:83:in
  `process_one'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/processor.rb:71:in
  `run'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/util.rb:16:in
  `watchdog'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/sidekiq-5.2.7/lib/sidekiq/util.rb:25:in
  `block in safe_thread'"
- "/opt/theforeman/tfm/root/usr/share/gems/gems/logging-2.3.0/lib/logging/diagnostic_context.rb:474:in
  `block in create_with_logging_context'"
~~~

Comment 7 Adam Ruzicka 2021-07-20 15:22:29 UTC
Not sure what to do with the status. The changed code lives in foreman_ansible_core, a new version containing the fix (4.1.1) just went out in upstream.

Comment 8 Danny Synk 2021-07-22 15:13:46 UTC
Steps to Test:
1. Register a host to Satellite and configure it for remote execution.
2. Using the "Ansible Playbook" job category and the "Ansible - Run playbook" job template, execute the following playbook on the host:

~~~
- hosts: all
  gather_facts: false
  tasks:
    - name: Handle the error
      block:
        - name: Print a message
          ansible.builtin.debug:
            msg: 'I execute normally'
    
        - name: Force a failure
          command: /bin/false
    
        - name: Never print this
          ansible.builtin.debug:
            msg: 'I never execute, due to the above task failing, :-('
      rescue:
        - name: Print when errors
          ansible.builtin.debug:
            msg: 'I caught an error, can do stuff here to fix it, :-)'
~~~

Expected Result:
When the rescue section is triggered, the playbook run returns an exit status of 0 and the job task is marked as successful by Satellite.

Actual Results:
When the rescue section is triggered, the playbook run returns an exit status of 0 and the job task is marked as successful by Satellite:

~~~
proxy_output:
  result:
  - output_type: stdout
    output: "[WARNING]: Callback disabled by environment. Disabling the Foreman callback\r\nplugin.\n"
    timestamp: 1626966492.524565
  - output_type: stdout
    output: "\n"
    timestamp: 1626966492.5246854
  - output_type: stdout
    output: "\r\nPLAY [all] *********************************************************************\n"
    timestamp: 1626966492.5247624
  - output_type: stdout
    output: "\r\nTASK [Print a message] *********************************************************\n"
    timestamp: 1626966492.5248268
  - output_type: stdout
    output: "\n"
    timestamp: 1626966492.5249183
  - output_type: stdout
    output: "ok: [host.example.com] => {\r\n    \"msg\": \"I execute
      normally\"\r\n}\n"
    timestamp: 1626966492.5249984
  - output_type: stdout
    output: "\r\nTASK [Force a failure] *********************************************************\n"
    timestamp: 1626966492.5250657
  - output_type: stdout
    output: "\n"
    timestamp: 1626966492.5251231
  - output_type: stdout
    output: 'fatal: [host.example.com]: FAILED! => {"ansible_facts":
      {"discovered_interpreter_python": "/usr/bin/python"}, "changed": true, "cmd":
      ["/bin/false"], "delta": "0:00:00.002874", "end": "2021-07-22 11:08:15.516364",
      "msg": "non-zero return code", "rc": 1, "start": "2021-07-22 11:08:15.513490",
      "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}

'
    timestamp: 1626966495.8053029
  - output_type: stdout
    output: "\r\nTASK [Print when errors] *******************************************************\n"
    timestamp: 1626966495.8054554
  - output_type: stdout
    output: "\n"
    timestamp: 1626966495.8055296
  - output_type: stdout
    output: "ok: [host.example.com] => {\r\n    \"msg\": \"I caught
      an error, can do stuff here to fix it, :-)\"\r\n}\n"
    timestamp: 1626966496.8094683
  - output_type: stdout
    output: |-
      PLAY RECAP *********************************************************************
      host.example.com : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=1    ignored=0
    timestamp: 1626966496.8097997
  exit_status: 0
~~~

Verified on Satellite 6.10, snap 10.

Comment 9 Mike McCune 2021-07-28 14:55:31 UTC
*** Satellite 6.8.6 Hotfix Available ***

1) Download tfm-rubygem-foreman_ansible_core-3.0.4.1-2.HFRHBZ1971395.el7sat.noarch.rpm from this bugzilla to your Satellite and Capsule servers

2) stop services:

satellite-maintain service stop

3) Install:

rpm -Uvh tfm-rubygem-foreman_ansible_core-3.0.4.1-2.HFRHBZ1971395.el7sat.noarch.rpm

4) restart:

satellite-maintain service start

5) resume operations

Comment 10 Mike McCune 2021-07-28 14:56:19 UTC
Created attachment 1806760 [details]
tfm-rubygem-foreman_ansible_core-3.0.4.1-2.HFRHBZ1971395.el7sat.noarch.rpm

Comment 15 errata-xmlrpc 2021-11-16 14:11:39 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Moderate: Satellite 6.10 Release), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2021:4702