Foreman Job template

I’ve a job template which I am running from foreman which does some validations (checking puppet, and other required services and stops them) and other stuff before it stops one of the hosts(linux aws instance) connected to it (for taking snapshot).

What I am looking for is: as I am running this template on particular host, I need to understand how can I run further jobs such as taking a snapshot of data drive attached to it, how can I rebuild the system (need to run a jenkins pipeline) and connect back to the same hostname in a single script?

what is the best way you suggest for this type of work? Jenkins - currently we don’t have ssh option enabled so Jenkins is ruled out.

Any other best way?

One possible thing is to split up these tasks and run it accordingly. However wanted to understand if there is any other best way?

Let me know if you need more information on the same.

I’ve posted the same in stack overflow but thought this might be the suitable place.

Thanks

Hi,

to my knowledge, there is currently no proper way to do this with just one Foreman Remote Execution job. REX is designed to run orchestration jobs on a per-host basis, not as a replacement for workflow tools or the like.

Possible solutions that come to my head:

  • Split it up and run seperately, as you already mentioned
  • If the SSH part(s) are the only thing hindering you from doing it all from Jenkins, you could call the REX job from Jenkins via Foremans API. The is an API endpoint available for executiong job templates ( POST /api/job_invocations). On your Foreman server, you can get the API Doc for your Version and all your installed Plugins from youreforeman.example.com/apidoc.
  • (The ugly solution) You could also use a host with the apropriate permissions (most probably your Foreman server) as a “management host” of sorts and write a Job template that does all the parts (SSH commands, calling Jenkins Pipeline, etc) from there, with the REX target host always beeing the same and the host to manage beeing it’s own input field. This works, but as mentioned is more of an ugly solution.

I hope this helps.

Regards

1 Like

Thanks for the detailed explanation, I have added a pre-condition to add private and public keys on the server upload/downlod into/from artifactory/vault post which I can connect to the hostname however post rebuild, keys will be removed so can’t connect without copying keys from repository which should be a diff script anyways.

Thanks.