5

Is there a way to deploy modules to Wildfly via scripting (as in, without manually modifying XML files)? I know about the jboss-cli.sh command to add module but is there a way to either directly modify my standalone.xml/domain.xml or do some equivalent thing that will tell Wildfly to load the module?


Said another way...

I've discovered two ways to deploy modules:

1) Hot deploy a jar directly by copying it into $KEYCLOAK_HOME/standalone/deployments (Per the README in that directory, this method is not recommended for production deployments but it works without any manual work afterward.)

2) run jboss-cli.sh --command="module add --name=com.example.MySpi" then manually edit standalone.xml (or domain.xml) to have your module in the "providers" list, like so:

<subsystem xmlns="urn:jboss:domain:keycloak-server:1.1">
  <web-context>auth</web-context>
  <providers>
    ...
    <provider>module:com.example.MySpi</provider>
  </providers>
  ...
</subsystem>

... and finally restart the server.

I'd like to use the recommended way, but without manually editing an XML file. Is there a recommended path for this?

inanutshellus
  • 9,683
  • 9
  • 53
  • 71
  • Can you add more of the section the `` tag is in or link to some documentation? More than likely you can add it via CLI with a management operation, but I'm not familiar with where that is located. – James R. Perkins Sep 27 '19 at 19:59

2 Answers2

9

You can do something like

jboss-cli.sh --command="/subsystem=keycloak-server:list-add(name=providers, value=module:com.example.MySpi)"

Basically you can script everything that is in standalone.xml with jboss-cli. To find out more how your configuration looks internally, you may try /subsystem=keycloak-server:read-resource(recursive=true) within jboss-cli.

Erhard Siegl
  • 557
  • 2
  • 8
3

Sorry, cannot add comments yet, so I'm adding this here.

I had to add the --connect option to the command above, otherwise it was complaining with no connection to the controller.

The whole command then would be:

jboss-cli.sh --connect --command="/subsystem=keycloak-server:list-add(name=providers, value=module:com.example.MySpi)"

ieggel
  • 891
  • 6
  • 12
  • 1
    Welcome to Stack Overflow, @ieggel, and thanks for the addition! Hopefully the question helped you too! – inanutshellus Oct 22 '19 at 14:06
  • 1
    Definitely helped me, as i was also searching for a way automatized way to register a provider module instead of manually modifying the XML file. Thanks !. – ieggel Oct 23 '19 at 13:05
  • If you don't want to start the server you can use the [embedded wildfly server](https://www.wildfly.org/news/2017/10/10/Embedded-Host-Controller/) to edit `standalone.xml` without starting keycloak. Just run `embed-server --server-config=standalone.xml` – Paul Jan 06 '21 at 06:39
  • 1
    It seems to be blocked in the **docker** version. – SalahAdDin Feb 07 '21 at 12:37