AAP/Tower - Passing "job_tags" to provisioning callback during its execution with curl - ansible

When executing provisioning callback on a host with curl as so:
/usr/bin/curl -k -H 'Content-Type: application/json' -d '{"host_config_key": "a_key", "job_tags": "a_tag"}' https://tower.host.domain/api/v2/job_templates/999/callback/
I can't find a way for the template to accept or respect the "job_tags" parameter to run a single role in a multirole playbook. Tried to select the job templates' Job Tags Prompt on launch "Prompt on launch" but with no luck here too. Is there an additional setting or a different way to pass tags to the callback?

Related

Curl using Environment variables in GitLab-ci.yml

I'm trying to send a slack notification using the .gitlab-ci.yml and I need to pass the Commit's message in the message like this:
"The version ${CI_COMMIT_TAG} Version is available!"
But i'm still not able to get the environment variable desired when receiving the notification on my channel and passing it like this in the file:
script:
- "curl -X POST -H 'Content-type: application/json' --data '{\"text\":\"The version ${CI_COMMIT_TAG} version is available!\"} ' https://hooks.slack.com/services/....../......"
Do you have any clues ? I'm not used to Curl and Yaml
Thanks and Have a good day!
--data '...'
Variable expansion in bash does not work within single quotes. Use double quotes instead.
Alternatively, use a data file to avoid formatting JSON inline:
curl -d "#data.json" ...

Curl command on windows not passing user:pass correctly

I'm using CURL to execute some API calls against a bitbucket server. The command is like this:
curl https://bitbucket.myserver.com/rest/api/1.0/projects/PRJ/repos/repo-slug/tags \
-u 'user:pass' \
-X POST \
-H 'Content-type: application/json' \
-d '{"name" : "test-tag", "message": "Test tag from curl", "startPoint": "master" }'
This is expected to create a tag on the master branch in the repo. This however fails complaining of incorrect username/password.
I then copy/paste the command into git-bash prompt - and it works as expected, completing successfully. I tried this with multiple user accounts. I also tried specifying only the username and then entering the password on command line - with the same results.
How can I get curl on windows to pass correct username/password to the server?

Why I can't use API for common user integrated with OIDC in ICP(IBM cloud private)

https://www.ibm.com/support/knowledgecenter/SSBS6K_2.1.0/apis/auth_manage_api.html
I try to use the API for common user integrated with OIDC, but the error msg shows:
{"error_description":"invalid_resource_owner_credential","error":"server_error"}
command as the following
curl -k -H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8" -d "grant_type=password&username=abc\#test\.com&password=ChangeMe\!\#\#&scope=openid" https://<cluster_access_ip>:8443/idprovider/v1/auth/identitytoken --insecure
But it is working fine for the administrator: admin/admin, so strange.
Issue is with the special character "!" which is used for history expansions in command line prompt.
You can use below command which works...
curl -k -H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8" -d "grant_type=password&username=abc#test.com&password=ChangeMe"'!'"##&scope=openid" https://<cluster_access_ip>:8443/idprovider/v1/auth/identitytoken --insecure
Have you configured the LDAP, created Teams and added users to the team? Did you check the logs on Master node /var/log/containers for platform-identity-manager, _platform-auth-service, *platform-identity-provider?

how to access whole nessus through shell script

I am trying to do a script to get me access of advance scan option of nessus in localhost. So I want advance scan operation through shell script without GUI. I want all operations like login, advance scan and export report are performed through shell script without GUI access.
Why do you want to do it with bash script?
You can do this much easier with the nessus API.
Have a look at the link below
https://github.com/jfalken/nessus_enterprise_rest_client
the simplest way of doing automatisation in nessus is to use the nessus API.
its located at https://NessusServerIP:8834/ - if you visit it, you will be greeted by the API-Documentation.
There are various API-Implementations available - if you google 'Nessus API client' you'll get a glimpse.
If you, as you said, want to to run bash-skripts than the simplest way is probably using CURL for the API-Requests.
A typical workflow will look like this:
authorize yourself to the NessusAPI (either via TOKEN or API-Key)
launch or configure a scan (and wait until it finished)
export a report (and wait until it finished)
download the exported report
CURL #1 (authorize using token):
curl -X POST --data '{"username":"NessusUser","password":"YourPassword"}' -k "https://NessusServerIp:8834/session"
--header "Content-Type:application/json" | python -m json.tool
..which will yield you following JSON yielding an Token which you need for the other API-Calls:
{"token": "e411e443521adee4496d79823a510cc68c5bf05aeda6e6eb"}
CURL #2 (launch a scan):
curl -X POST -H 'X-Cookie: token=e411e443521adee4496d79823a510cc68c5bf05aeda6e6eb' -H 'Content-Type:application/json'
--data '{"scan_id":"21", "alt_targets":[127.0.0.1]}'
-k "https://NessusServerIp:8834/scans/21/launch" | python -m json.tool
...which will be answered with a JSON like this, containing the ID of the just startet scan:
{"scan_uuid":"c1c30d8f-5f79-2e4b-2d03-05b8b3c595f1e768e03195abdfa2"}
CURL #3 (exporting a scan):
curl -X POST -H 'X-Cookie: token=766ef7a2302780c189ba563b89c5eb3706140c0ef1e4de8b' -H
'Content-Type:application/json' --data '{"scan_id":"33", "format":"html"}' -k
"https://NessusServerIP:8834/scans/33/export" | python -m json.tool
...which will yield this JSON response, containing a token to the exported file and the file_id:
{"token":"3e13ab381c480caa1e377411c0b561970c46e5d78894c5a0cb2be0e7f00fefe0","file":1434780027}
...so now we are ready to download the report. in this case, since i have specified "format: html" in the last call, its a .html you will need to safe the outcome into.
Curl #4 (download exported report):
curl -X GET -H 'X-Cookie: token=7d155aef4359d02addea29d8d56bca4a5045ca61efeb38ee' -H 'Content-Type:application/json'
--data '{"scan_id":"21", "alt_targets":127.0.0.1}'
-k "https://NessusServerIP:8834/scans/17/export/945237343/download" > report.html
...which should leave you with a report.html in the folder you started your script.
Now... how do you automatize this? Well write a Bash-Skript, put in this calls, parse the answers to extract the information you need - and then enjoy! :)
ps: i use the python -m json.tool to beautify the otherwise not very beautiful output of CURL.
Hope i have helped,
Gewure

Get Jenkins job status by using curl

I know, that there is a way to enable or disable jenkins job by using commands
curl -u user:password -X POST http://server/job/jobname/enable
curl -u user:password -X POST http://server/job/jobname/disable
But what I need - is to get the status of job "enabled/disables" and write it to the bash $status variable.
Is there a way to do it?
You can check if job is enabled or disabled using the API
http://server:port/job/jobname/api/xml?xpath=*/buildable
So, with crumb, you can use something like this:
CRUMB=$(curl -s 'http://USER:PASSWORD#SERVER:PORT/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)')
myStatus=$(curl -X POST -H "$CRUMB" "http://USER:PASSWORD#SERVER:PORT/job/jobname/api/xml?xpath=*/buildable")
And in variable myStatus you get
<buildable>true</buildable>
or
<buildable>false</buildable>

Resources