Using the OpenStack CLI, I am creating server instances and need to pass custom properties (--property) into the init script referenced by the --user-data parameter.
So, my invocation looks something like this:
openstack server create myServer \
...other args...
--user-data ./initScript.sh \
--property "foo=bar"
In initScript.sh how do I get access to the foo property and it's value?
Elements defined with --property go into the meta element of the metadata. [source]
If you run
curl http://169.254.169.254/openstack/2018-08-27/meta_data.json
You'll get
{
"hostname": "test.novalocal",
…
"meta": {
"foo": "bar",
…
},
…
}
And to parse out the value in a shell script, you can use for example:
$ curl http://169.254.169.254/openstack/2018-08-27/meta_data.json \
| jq -r '.meta.foo'
bar
See documentation for the Metadata Service for more information on the format and various methods available to retrieve this information.
Related
I have a project with many branches and I would like to list all merge requests from a specific branch from the console.
I found the merge requests API and I also found that I need an HTTP request to do it from this issue like this:
curl --header "PRIVATE-TOKEN: XXXXXX" -X GET "https://gitlab.example.com/api/v3/projects/project_name/merge_requests?source_branch=XXXXXX"
But I haven't figured out yet how. The response is this:
{"message":"404 Project Not Found"}
Although the name of the project is correct.
project_name in your example should actually be fully namespaced project name or project ID.
eg: If your project called myproject is under a group called mygroup, the api call would be:
curl --header "PRIVATE-TOKEN: XXXXXX" -X GET "https://gitlab.example.com/api/v3/projects/mygroup%2Fmyproject/merge_requests?source_branch=XXXXXX"
If you want to use project ID instead, you can get it at https://gitlab.com/api/v4/projects/[project path URL encoded]
Ref:
HOW to check id of project in gitlab
I am defining a shell script in one of the stages in my Jenkinsfile. How can I access a variable that I define in my Jenkinsfile with the shell script?
In below scenario , I am writing the value of the shell variable to a file and reading into a groovy variable. Is there a way to pass data from shell to groovy without writing it to file system?
unstash 'sources'
sh'''
source venv/bin/activate
export AWS_ROLE_ARN=arn:aws:iam::<accountid>:role/<role name>
layer_arn="$(awssume aws lambda list-layer-versions --layer-name dependencies --region us-east-1 --query \"LayerVersions[0].LayerVersionArn\" | tr -d '\"')"
echo $layer_arn > layer_arn
'''
layer_arn = readFile('layer_arn').trim()
You can can shell command line, providing variable value.
sh "some stuff $my_var"
You can defined environment variable and use it within your shell
withEnv(["MY_VAR=${my_var}") {
sh 'some stuff'
}
Regards
I'm trying to figure it out how to retrieve the latest version of each image stored in the Docker repo using AQL. The following code gives me all the versions but I couldn't find a way to get only the latest one for each asset.
curl -u "username:password" -i -X POST <host>/artifactory/api/search/aql -H "Content-Type: text/plain" -d '
items.find(
{
"repo":{"$eq":"my-docker-repo"},
"$or":[
{"path": { "$match" : "application/*" }},
{"path": { "$match" : "service/*" }}
]
}
).include("repo", "path", "name", "created").sort({"$desc" : ["path","created"]})'
Thanks!
Andre
The brainiacs over at R&D created a cool util that also serves the purpose your'e looking to achieve, you can get it here. You can also check the sources for the exact AQL query it runs if you want to implement something similar for your own usecase.
I'm new to OpenStack and I used DevStack to configure a multi-node dev environment, currently compound of a controller and two nodes.
I followed the official documentation and used the development version of DevStack from the official git repo. The controller was set up in a fresh Ubuntu Server 16.04.
I automated all the steps described in the docs using some scripts I made available here.
The issue is that my registered VM images don't appear on the Dashboard. The image page is just empty. When I install a single-node setup, everything works fine.
When I run openstack image list or glance image-list, the image registered during the installation process is listed as below, but it doesn't appear at the Dashboard.
----------------------------------------------------------
| ID | Name | Status |
----------------------------------------------------------
| f1db310f-56d6-4f38 | cirros-0.3.5-x86_64-disk | active |
----------------------------------------------------------
openstack --version openstack 3.16.1
glance --version glance 2.12.1.
I've googled a lot but got no clue.
Is there any special configuration to make images available in multi-node setup?
Thanks.
UPDATE 1
I tried to set the image as shared using
glance image-update --visibility shared f1db310f-56d6-4f38-b5da-11a714203478, then to add it to all listed projects (openstack project list) using the command openstack image add project image_name project_name but it doesn't work either.
UPDATE 2
I've included the command source /opt/stack/devstack/openrc admin admin inside my ~/.profile file so that all environment variables are set. It defines the username and project name as admin, but I've already tried to use the default demo project and demo username.
All env variables defined by the script is shown below.
declare -x OS_AUTH_TYPE="password"
declare -x OS_AUTH_URL="http://10.105.0.40/identity"
declare -x OS_AUTH_VERSION="3"
declare -x OS_CACERT=""
declare -x OS_DOMAIN_NAME="Default"
declare -x OS_IDENTITY_API_VERSION="3"
declare -x OS_PASSWORD="stack"
declare -x OS_PROJECT_DOMAIN_ID="default"
declare -x OS_PROJECT_NAME="admin"
declare -x OS_REGION_NAME="RegionOne"
declare -x OS_TENANT_NAME="admin"
declare -x OS_USERNAME="admin"
declare -x OS_USER_DOMAIN_ID="default"
declare -x OS_USER_DOMAIN_NAME="Default"
declare -x OS_VOLUME_API_VERSION="3"
When I type openstack domain list I get the domain list below.
----------------------------------------------------
| ID | Name | Enabled | Description |
----------------------------------------------------
| default | Default | True | The default domain |
----------------------------------------------------
As the env variables show, the domain is set as the default one.
After reviewing all the installation process, the issue
was due to an incorrect floating IP range defined inside the local.conf file.
The FLOATING_RANGE variable in such a file must be defined as a subnet of the node network. For instance, my controller IP is 10.105.0.40/24 while the floating IP range is 10.105.0.128/25.
I just forgot to change the FLOATING_RANGE variable (I was using the default value as shown here).
I get an error when trying to run it:
~/projects/test-app
/usr/local/bin/meteor:3
# This is the script that we install somewhere in your $PATH (as "meteor")
Here is the command I run:
pm2 start meteor-pm2.json
And here is meteor-pm2.json:
{
"name" : "test-app",
"script" : "/usr/local/bin/meteor",
"MAIL_URL":"smtp://yourmail_configuration_here",
"MONGO_URL":"mongodb://localhost:27017/meteor",
"ROOT_URL":"https://www.mysite.com/",
"PORT":"3000",
"out_file":"/home/josh/logs/app.log",
"error_file":"/home/josh/logs/err.log"
}
I also try this:
cat start
#!/bin/bash
MONGO_URL="mongodb://localhost:27017/meteor"
PORT=3000
ROOT_URL="https://www.mysite.com/"
/usr/local/bin/meteor
and I run it with:
pm2 start ./start -x interpreter bash
and I get:
/usr/local/bin/meteor
^
ReferenceError: usr is not defined
when i modify the bash script by adding the export:
#!/bin/bash
export MONGO_URL="mongodb://localhost:27017/meteor"
export PORT=3000
export ROOT_URL="https://www.mysite.com/"
/usr/local/bin/meteor
I get:
export - SyntaxError: Unexpected reserved word
Any ideas what am I doing wrong?
Is pm2 trying to run the bash script in it's own special script interpreter that doesn't allow the use of export?
I believe this process.json syntax is more correct:
{
"apps": [
{
"name": "myAppName",
"script": "./bundle/main.js",
"log_date_format": "YYYY-MM-DD",
"exec_mode": "fork_mode",
"env": {
"PORT": 3000,
"MONGO_URL": "mongodb://127.0.0.1/meteor",
"ROOT_URL": "https://myapp.example.com/",
"BIND_IP": "127.0.0.1"
}
}
]
}
then I just start it using run.sh which contains:
#!/bin/sh
#
# This shell script starts the actual
# app in the production environtment.
#
pm2 start process.json -i max # Enable load-balancer and cluster features
Note: the BIND_IP env var is there to change it from the default (0.0.0.0). The 0.0.0.0 would make the app accessible around the ssl proxy layer (if you use SSL/TLS with nginx or some other web server and the BIND_IP is set to 0.0.0.0 then pretty much anyone could access it via http://myapp.example.com:3000 around the encrypted layer, unless you block that port in your web server's configuration).
This is how I got my meteor app (Telescope) working
ROOT_URL=http://localhost:3000 PORT=3000 MONGO_URL=mongodb://127.0.0.1:27017/Telescope pm2 start main.js
inside .meteor/local/build
Meteor isn't actually running from /usr/local/bin/meteor, that script is only used for bootstrapping etc, that when done redirects to ~/.meteor/meteor
From /usr/local/bin/meteor:
# All this script does is exec ~/.meteor/meteor. But what if you don't have it
# yet? In that case, it downloads a "bootstrap tarball", which contains the
# latest version of the Meteor tools, and plops it down at ~/.meteor. In fact,
# once you've run this once, you don't even really need this script: you can put
# ~/.meteor/ into your PATH, or a symlink to ~/.meteor/meteor into some other
# PATH directory. No special permissions needed!
So what you need to do is change your script pointer to use meteor in your "Warehouse dir" (~/meteor/meteor)
This means that pm2 expects some syntax and finds another in the start script. In order to direct it to the right syntax, add this to your config.json file:
"interpreter" : "bash"
P.S.: addition of this parameter to the command line didn't work