12 Replies Latest reply on Jan 29, 2020 9:40 AM by reisub83

    Using literal variables in a Wildfly OFFLINE CLI

    reisub83

      I'd like to use an offline Wildfly CLI to add system properties

      The problem is that the value should be a variable

      This is the desired result:

              <property name="user.country" value="${country}"/> 

      the problem is that the CLI try to resolve the variable

      [disconnected /] embed-server [standalone@embedded /] /system-property=user.country:add(value="${country}") { "outcome" => "failed", "failure-description" => "WFLYCTL0211: Cannot resolve expression '${country}'", "rolled-back" => true } 

      I tried to escape the '$' with '$$' or '\$', but it doesn't worked.

      Or rather, with '$$' I got

      <property name="user.language" value="$${countrylowercase}"/> 

      If I run the server an retry with a connect CLI , it works normally, because the resolve-parameter-values is false in jboss-cli.xml

      How to do this offline?

      As a workaround I'm doing a sed on the resultef standalone to replace '$${' with '${'  , but I don't like it too much...

      Thanks

        • 1. Re: Using literal variables in a Wildfly OFFLINE CLI
          mayerw01
          • 2. Re: Using literal variables in a Wildfly OFFLINE CLI
            reisub83

            Sorry, I can't access that link

            • 3. Re: Using literal variables in a Wildfly OFFLINE CLI
              mayerw01

              This page describes 2 approaches.

               

                   1. via properties

                • Use the "--properties=/path/to/file.properties" to pass in the properties.

                             Example: myvar=value

                • The notation in the CLI script is then as per usual "${myvar}"

                             Example: /subsystem=datasources/xa-data-source=MyDS/statistics=pool:read-resource(include-runtime=${myvar})

               

                   2. via bash scripting

                • Example:

               

                   #!/bin/bash

                   PASSWORD=secret

                   KEYFILE=ourKeyFileName

                   FQHN=host.domain.com

                   $JBOSS_HOME/bin/jboss-cli.sh --connect <<EOF

                        batch

                             /subsystem=web/connector=https:add(secure=true,name=https,socketbinding=https,scheme=https,protocol="HTTP/1.1")

                             /subsystem=web/connector=https/ssl=configuration:add(name=ssl,password="$PASSWORD",certificate-keyfile="\${jboss.server.config.dir}/$KEYFILE.jks",key-alias="$FQHN")

                        run-batch

                        exit

                   EOF

              • 4. Re: Using literal variables in a Wildfly OFFLINE CLI
                reisub83

                Thanks

                 

                actually the properties file is my approach, this is what I'm running

                 

                ${WILDFLY_HOME}/bin/jboss-cli.sh -Djboss.server.base.dir=/home/user/server/basedir --file=/home/user/properties.cli


                and in the .cli file

                 

                embed-server
                
                /system-property=user.language:add(value="${countrylowercase}")
                /system-property=user.region:add(value="${country}")
                /system-property=user.country:add(value="${country}")
                
                
                stop-embedded-server

                 

                But I've also tried the inline mode in a bash script , same results, the cli tried to resolve the variables

                • 5. Re: Using literal variables in a Wildfly OFFLINE CLI
                  mayerw01

                  Your file contain cli commands. But as mentioned above you should first create a properties file like

                  country=Amerika

                  countrylowercase=amerika

                   

                  You should then provide this flle to the jboss-cli

                   

                  like

                  ${WILDFLY_HOME}/bin/jboss-cli.sh -Djboss.server.base.dir=/home/user/server/basedir --file=/home/user/commands.cli  --properties=/home/user/properties.cli

                  • 6. Re: Using literal variables in a Wildfly OFFLINE CLI
                    reisub83

                    But this is not what I want to achieve...

                     

                    This is how the standalone should results:

                     

                    ...   

                    </extensions>

                     

                    <system-properties>

                         <property name="file.encoding" value="UTF-8"/>

                         <property name="user.language" value="${countrylowercase}"/>

                         <property name="user.region" value="${country}"/>

                         <property name="user.country" value="${country}"/>

                    </system-properties>

                     

                    <management>

                    ...

                    • 7. Re: Using literal variables in a Wildfly OFFLINE CLI
                      mayerw01

                      So why don't you just set uo your properties file like

                      country=$country

                      countrylowercase=$countrylowercase

                      • 8. Re: Using literal variables in a Wildfly OFFLINE CLI
                        reisub83

                        Already tried, same result : "Cannot resolve expression"

                         

                         

                        • 9. Re: Using literal variables in a Wildfly OFFLINE CLI
                          mayerw01

                          At least in my environment this is working as expected.

                           

                          cat cli.commands

                              embed-server 

                               

                              /system-property=user.language:add(value="${countrylowercase}") 

                              /system-property=user.region:add(value="${country}") 

                              /system-property=user.country:add(value="${country}") 

                                         

                              stop-embedded-server 

                           

                          cat cli.property

                          country=$country

                          countrylowercase=$countrylowercase

                           

                           

                          $JBOSS_HOME/bin/jboss-cli.sh --properties=./cli.property --file=./cli.commands

                          {"outcome" => "success"}

                          {"outcome" => "success"}

                          {"outcome" => "success"}

                           

                           

                          what is your WildFly version and where do you get this error message?

                          • 10. Re: Using literal variables in a Wildfly OFFLINE CLI
                            reisub83

                            Now I begin to understand.

                             

                            What I tried is different but I just assumed it was idempotent:

                             

                            I had set the variables directly in the cli script:

                             

                                embed-server

                             

                                set country=${country}

                                set countrylowercase=${countrylowercase}

                             

                             

                                /system-property=user.language:add(value="${countrylowercase}")

                                /system-property=user.region:add(value="${country}")

                                /system-property=user.country:add(value="${country}")

                             

                                stop-embedded-server

                             

                            I need to try with the dedicated properties file

                            • 11. Re: Using literal variables in a Wildfly OFFLINE CLI
                              reisub83

                              # cat variables.cli

                              country=${country}

                              countrylowercase=${countrylowercase}

                               

                              # cat properties.cli

                              embed-server

                               

                               

                              /system-property=user.language:add(value="${countrylowercase}")

                              /system-property=user.region:add(value="${country}")

                              /system-property=user.country:add(value="${country}")

                               

                              stop-embedded-server

                               

                               

                              ${WILDFLY_HOME}/bin/jboss-cli.sh -Djboss.server.base.dir=/home/user/server/base/ --properties=/home/user/variables.cli --file=/home/user/properties.cli

                               

                               

                              Running properties.cli

                              {

                                  "outcome" => "failed",

                                  "failure-description" => "WFLYCTL0211: Cannot resolve expression '${countrylowercase}'",

                                  "rolled-back" => true

                              }

                               

                               

                               

                               

                               

                              this is a Wildfly 18

                              • 12. Re: Using literal variables in a Wildfly OFFLINE CLI
                                reisub83

                                Ok so

                                 

                                this is not working

                                 

                                # cat variables.cli

                                country=${country}

                                countrylowercase=${countrylowercase}

                                 

                                this is working

                                 

                                cat cli.property

                                country=$country

                                countrylowercase=$countrylowercase

                                 

                                thanks for your help and your time!