Module instance sort en erreur si la procédure n’est pas allé jusqu’au bout

This commit is contained in:
Benjamin Bohard 2021-08-30 11:37:09 +02:00
parent 2e94186bef
commit b553f77ead
1 changed files with 22 additions and 17 deletions

View File

@ -335,24 +335,30 @@ def run_module():
for expectation_name, response in module.params['variables'].items():
expectations.set_expectation_response_by_name(expectation_name, response)
instance_process = pexpect.spawn(cmd, encoding='utf-8', timeout=60)
try:
instance_process = pexpect.spawn(cmd, encoding='utf-8', timeout=60)
some_index = 0
while some_index < nb_expectations:
p = instance_process.expect(patterns)
if p == 0:
break
if p == 1:
print(f'Some missing expectations for {instance_process.before}{instance_process.after}')
break
pattern = patterns[p]
for expectation in expectations.get_expectations_by_pattern(patterns[p]):
if expectation.is_the_one(instance_process.before):
expectation.answer(instance_process)
some_index = 0
while some_index < nb_expectations:
p = instance_process.expect(patterns)
if p == 0:
break
some_index += 1
result['changed'] = True
result['msg'] += f"Module {result['module']} instanciated"
if p == 1:
print(f'Some missing expectations for {instance_process.before}{instance_process.after}')
break
pattern = patterns[p]
for expectation in expectations.get_expectations_by_pattern(patterns[p]):
if expectation.is_the_one(instance_process.before):
expectation.answer(instance_process)
break
some_index += 1
result['changed'] = True
result['msg'] += f"Module {result['module']} instanciated"
module.exit_json(**result)
except Exception as err:
result['msg'] += err
result['changed'] = True
module.fail_json(**result)
@ -369,7 +375,6 @@ def run_module():
# in the event of a successful module execution, you will want to
# simple AnsibleModule.exit_json(), passing the key/value results
module.exit_json(**result)
def main():