-
1. Re: Using literal variables in a Wildfly OFFLINE CLI
mayerw01 Jan 27, 2020 11:57 AM (in response to reisub83)You can use cli scripting like described here JBoss EAP 6 : using variables in CLI scripts (jboss-cli.sh) - Red Hat Customer Portal
-
2. Re: Using literal variables in a Wildfly OFFLINE CLI
reisub83 Jan 28, 2020 4:15 AM (in response to mayerw01)Sorry, I can't access that link
-
3. Re: Using literal variables in a Wildfly OFFLINE CLI
mayerw01 Jan 28, 2020 5:08 AM (in response to reisub83)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 Jan 28, 2020 5:54 AM (in response to mayerw01)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 Jan 28, 2020 8:51 AM (in response to reisub83)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 Jan 28, 2020 10:17 AM (in response to mayerw01)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 Jan 28, 2020 10:49 AM (in response to reisub83)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 Jan 28, 2020 12:04 PM (in response to mayerw01)Already tried, same result : "Cannot resolve expression"
-
9. Re: Using literal variables in a Wildfly OFFLINE CLI
mayerw01 Jan 29, 2020 4:17 AM (in response to reisub83)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 Jan 29, 2020 5:38 AM (in response to mayerw01)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 Jan 29, 2020 8:46 AM (in response to mayerw01)# 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 Jan 29, 2020 9:40 AM (in response to mayerw01)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!