Search code examples
jbosswildfly

How can I read first host name in jboss-cli


I'm writing a jboss-cli script which manipulates the servers in a host.xml file, however I'm not able to retrieve the host name (the name has to be dynamic).

I am able to get a list of the current host names with the following

set host=`:read-children-names(child-type=host)`

but the value returned is a list, not a single item.

echo $host
["master"]

Is there a way to get the first host in the list? Or is there an alternative way to read the current host? (we're never expecting more than one)

Thanks if you can help!

EDIT: My workaround was to use the COMPUTERNAME environment variable (Wildfly is running on Windows), knowing that the Wildfly host name should always be the same as the computer name. (This customer's servers are all set up in this way). However, I would prefer to do this properly.


Solution

  • Given you want to get the host name in use, you can use the local-host-name attribute.

    set host=`:read-attribute(name=local-host-name)`
    

    That produces something like:

    [domain@embedded /] echo $host
    primary