Automating Apache Karaf

Hello everyone.

I’m working on a set of modules for controlling an Apache Karaf OSGi node; particularly fetching, installing, and removing OSGi bundles. Karaf has a built in SSH2 server, but it does not have a “BASH” implementation (all commands are specific to Karaf). I can confirm that Ansible has no problem connecting via SSH to Karaf (the connection simply fails on the first command “mkdir -p $HOME/.ansible/…”).

I’ve tried creating my own Connection Plugin, but in debugging, I’ve realized that connections are really just a way for Ansible to ship shell commands and scripts to be executed on the remote host (which makes sense).

I’m now left in this awkward position of having to use a local connection and manually connect via SSH in the module to execute commands (one at a time). Do you have any recommendations?

Sounds like you might be in a bit of a hard position, though you might be able to leverage ansible-pull instead.

Ansible-pull works by running Ansible commands it downloads from git, and runs things locally.

–Michael

I have a Karaf setup with fuse-esb, not sure how they are different, but fuse has a “client” script which I use to launch commands. Here is a snippet of my task:

  • name: Execute Command in Karaf
    shell: “{{app_dir}}/{{fuse_esb_home}}/bin/client -h localhost -a {{karaf_port}} -u {{karaf_user}} -p {{karaf_password}} {{karaf_command}}”

HTH,

Serge

Thank you. I’ve done something kind of ghetto, but it works. I’ve described it on Serge’s post.

Thanks for the advice. I’ve actually got it working using two methods, both executed at the Module level (not the connection):

  1. Local “client” script, as you suggested.
  2. An SSH call using Paramiko.

If you run the script on connection=local, Paramiko will connect directly to with the Karaf SSH shell and execute commands. If it’s run against the target server (assuming this is the Linux/UNIX instance hosting Karaf), it will execute via client script. I translate the command based on the mechanism, and use the same code to interpret the response. Personally, I prefer executing locally and connecting with the Karaf shell. This way you can provide limited access to the remote machine (if that’s a concern of yours) and it actually executes faster (since there is no copying of scripts over to the local machine and then calling the client script which is actually an SSH connection…).

I’ll post my project on Github in a day or so.

Hello Richard,

I understand it has been long time since you wrote this post. I need a similar solution for deploying karaf features, would appreciate if you can share your script. I could not find the git repo, would be grateful if you can share.

Thanks,
Ram