Description of problem: A state machine's on_exit method runs before the main method if the main method is an embedded Ansible playbook. The on_exit does not wait for the playbook to complete (or even start). Version-Release number of selected component (if applicable): 5.9.0.22 How reproducible: Every time Steps to Reproduce: 1. Create a one-state state machine that has a single-line on_entry method as follows: $evm.log(:info, "In on_entry at #{Time.now}...") ... a single-line on_exit method as follows: $evm.log(:info, "In on_exit at #{Time.now}...") ... and a main method that is an embedded Ansible playbook as follows: --- - name: Print the time hosts: localhost tasks: - debug: msg="In Ansible method at {{ ansible_date_time.iso8601 }} " 2. Run the state machine from simulation Actual results: The lines written to automation.log are: <AEMethod on_entry> In on_entry at 2018-03-16 11:48:10 +0000... <AEMethod on_exit> In on_exit at 2018-03-16 11:48:11 +0000... The output from the job is: TASK [debug] ******************************************************************* ok: [localhost] => { "msg": "In Ansible method at 2018-03-16T11:48:45Z " } It can be seen that the playbook runs many seconds after on_exit has completed. Expected results: The on_exit method should run after the playbook has completed Additional info:
Hi Peter, We had some discussions on this issue a while back. If the on_exit is not called on a retry, you dont have the ability to process the retry. Shouldn't the on_exit method be checking if its in retry and bailing and waiting for the task to finish. If we called it only when the step finishes then we miss out on the retry opportunity. Thanks, Madhu
Hi Madhu I'm not sure I understand the context of retrying, wouldn't you always want the on_exit method to be called once the main method has finished, regardless of whether a retry was triggered? I'm thinking for example of generic 'update_status' methods such as: update_status(status => 'Processed Preprocess') You'd only want this to run once the main method has completed.
Tina - Please work with Madhu on this issue.
Further testing has shown that the on_exit method is run just once with an ae_result of 'retry'. I added this single line to on_exit: $evm.log(:info, "In on_exit, ae_result = #{$evm.root['ae_result']}") This only runs once, and prints: '<AEMethod on_exit> In on_exit, ae_result = retry' I believe that it should also run when the Ansible method has completed, and ae_result would be 'ok'?
This works using a catalog service. Simulation does not handle retires. Working as designed. Billy
The state machine on_exit is still an issue. Peter had a second issue where it appears as though the retry wasn't working properly. This second issue has been resolved.
We're working on a fix now.
https://github.com/ManageIQ/manageiq-automation_engine/pull/168
New commit detected on ManageIQ/manageiq-automation_engine/master: https://github.com/ManageIQ/manageiq-automation_engine/commit/b1e7e41be36166245dfcba7e8c33f3c2f2eae142 commit b1e7e41be36166245dfcba7e8c33f3c2f2eae142 Author: Tina Fitzgerald <tfitzger> AuthorDate: Wed Mar 28 17:33:49 2018 -0400 Commit: Tina Fitzgerald <tfitzger> CommitDate: Wed Mar 28 17:33:49 2018 -0400 Change the Ansible Playbook method ae_result value from retry to async_launch and change the state machine processing to skip the on_exit for the async_launch and change the value to retry. https://bugzilla.redhat.com/show_bug.cgi?id=1557310 lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_playbook_method.rb | 2 +- lib/miq_automation_engine/engine/miq_ae_engine/miq_ae_state_machine.rb | 16 +- spec/engine/miq_ae_state_machine_steps_spec.rb | 14 + spec/miq_ae_playbook_method_spec.rb | 6 +- 4 files changed, 28 insertions(+), 10 deletions(-)
Fixed and verified in 5.10.0.6.20180725145922_d299ff5. on_exit is not called when the playbook was launched in a state machine.