Home > Software engineering >  Handling Jenkins status failure from exit code of Ansible plabook
Handling Jenkins status failure from exit code of Ansible plabook

Time:01-13

Looking to handle system reboot on Linux with Ansible & running it as part of playbook along with other asks.

Seeing exit code as 4 & due to which Jenkins job is resulting in failure, though it has rebooted the machine.

Is there a way to handle this failure either from calling of ansible playbook from Jenkins or from within the playbook.

Tried even something like below apart from plain reboot: task as well, but still no luck. Kindly suggest alternative method of handling this.

- name: Reboot the machine
  shell: |
    shutdown -r now && exit 0 
  ...
  ....

Error is as per below

Reboot the machine ---------------------------------------- 1.02s
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 4
Finished: FAILURE

CodePudding user response:

According the given description, task and error message

ERROR: script returned exit code 4

the error itself means Error Code 4 EINTR Interrupted system call or even Network Error in your example, the devices which Ansible connect to are going to restart faster than Ansible and the module shell can maintain his own connection. Meaning, close and disconnect the session.

You may try with

- name: Schedule reboot in 1 min
  shell:
    cmd: "shutdown -r  1"
  register: result

- name: Show result
  debug:
    var: result

or better reboot module – Reboot a machine.

Further Reading

about an approach which was used in the past for Linux systems

and

  • Related