How to patch and reboot a server using the the "Foreman Remote Execution" plugin without lossing the control of the job during the reboot of the server

Hi there,

Well I would like to know if there is way to use to the Remote Execution Plugin to orchestrate the patching of a server and its after restart with out losing the control of the Job and see it as failed task. As you could see at the screenshot below.

Any other idea as an alternative is great as well.

Regards.

Fix for the uninitialized constant is merged into upstream REX core, but wasn’t relesed yet. However you can quite easily patch it by hand, see https://github.com/theforeman/foreman_remote_execution/commit/49f59f9a614197cab26c2f80cff80ac844e5ff6f . Just add the line into /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_remote_execution_core-*/lib/foreman_remote_execution_core/script_runner.rb.

Another way to approach it would be to use the Power Action template which ships with REX instead of just putting “reboot” at the end of the script.

<%= render_template("Power Action - SSH Default", :action => "restart" %>

Even with this in place the job may still fail under certain circumstances, so I’ve seen people cloning the power action template and replacing its contents with the following and using the clone instead.

echo <%= input('action') %> host && sleep 3
<%= case input('action')
      when 'restart'
        'shutdown -r +1'
      else
        'shutdown -h now'
      end %>

Hi Adam, thank you for your quick answer. I am going to try both options and I will share with you my results and thoughts.

Once again, thank very much you were so helpful to me.

Hi again Adam,

Using the option you suggested of rendering the power action template for restarting the server at the end of my script works perfectly.

But now, and as I meant with not losing the control of the job during the server restart i would like to continue executing tasks aftrr the reboot of the sever as post reboot tasks in the same job.

To check for instance the server fulfill some requirements fter the reboot. Like checking for up and running services, etc…

Is this possible, to make the job wait for the server come to live again without failing?

Regards.

Hi,

sadly what you’re describing is not possible so far and has to be done by running a follow-up job by hand after the first one finishes. We have an issue[1] for tracking this feature, but as far as I know noone started working on that yet.

[1] - Feature #15872: Ability to monitor whether a host is up or not, after a reboot through the remote execution feature. - Foreman Remote Execution - Foreman

Ok. I see… Thank you for your help.

I will try to implement my solution using the Ansible, but first I have to make the Ansible plugin works. :slight_smile:

Again, thank you so much.

Hi,

I don’t intend to hijack your thread but since we are discussing remote execution here, can you please tell what type of remote execution you have tried so far?

Also, can you please point me to a documentation for setting up remote execution? There are few versions of the remote execution plugin and I got confused about what to pick up and what not to.

Thanks,

Yes sure, don’t worry.

First of all,the remote execution plugin’s installation documentation I am using is the one belonging to version 1.3.

https://theforeman.org/plugins/foreman_remote_execution/1.3/index.html

And about your other question, I just want to run a script which patch the the target server, reboot it and then perform some post-booting tests on the server as part of the same job.

Regards.

Yes, REX is legging that feature it cannot wait till reboot finishes even there are no email notifications for Job results.