I would like to create a curl output live in a single shell command, to log a output from an Ansible job in realtime filling a log file.
I've tried this command:
curl -f -k -N -H 'Content-Type: application/json' -XPOST \
--user admin:awxsecret \
http://192.168.42.100/api/v2/jobs/1620/
...but it only returns the output generated thus far, not waiting for newly-generated content.
As #charles-duffy said: "AWX does support websockets" I will work with this solution.
Related
Can some one tell how to pass multiple extra_vars variables from the command line which will run the Job Template in Tower?
I've followed Ansible documentaion https://docs.ansible.com/ansible-tower/latest/html/userguide/job_templates.html#passing-extra-variables-to-provisioning-callbacks
curl -f -H 'Content-Type: application/json' -XPOST \
-d '{"host_config_key": "efref3d9-740f-429c-43r2-15t326b76", "extra_vars": "{\"Job_ID\": \"24\"},{\"job_templates\": \"test99\"}"}' \
https://tower-ansible.com:443/api/v2/job_templates/822/callback/ -k
For single variable it's working. Below curl command works with single extra variable
curl -f -H 'Content-Type: application/json' -XPOST -d '{"host_config_key": "efref3d9-740f-429c-43r2-15t323b76", "extra_vars": "{\"job_id\": \"24\"}"}' https://tower-ansible.com:443/api/v2/job_templates/822/callback/ -k
According the documentation about Passing Extra Variables to Provisioning Callbacks you have referenced you may
Use the following JSON format as an example when adding your own extra_vars to be passed
"extra_vars": {"variable1":"value1","variable2":"value2",...}
instead of as in your provided example
"extra_vars": {"variable1":"value1"},{"variable2":"value2"}
I wrote a curl script to pull data from my api url into my unix terminal. But when I run the script below, I get a blank space as my output, rather than data from the api url. I don't get any standard error message, just a blank space followed by $ to enter a new command.
#!/bin/bash
INSTANCE_NAME="https://servicenow.com/ServiceNowData/tickets?ticks=4320000"
DATA_OUTPUT=$(curl -s -k -X GET -H "accept: application/json" $INSTANCE_NAME)
echo $DATA_OUTPUT
Page 404. And -H "Accept-Encoding: application/json"
I 'd like to post directly a json object from a url(json) to another url
so the command goes as follows:
curl "<resource_link>.json" -o sample.json
curl -X POST "<my_link>" "Content-type: application/json" -d #sample.json
I 'd like to avoid this, so what is the solution? Is it something like that?
curl -X POST "<my_link>" "Content-type: application/json" -d "curl <resource_link>.json"
But it does not work? Also, this one post Stream cURL response to another cURL command posting the result
does not explain thouroughly and it is not working
Yes,
curl
manual explains the '#' but it does not explain about using another curl
Alternatievely, if I could save somewhere temporarily the 1st cURL response and use it in the other command(but not in a file)
You don't want -x POST in there so let's start with dropping that.
Send the results from the first transfer to stdout by not using -o, or telling -o to use stdout with -o-, and
Make sure your second transfer accepts the data to send on stdin, by using -d#-.
curl "<link>.json" | curl "<link2>" -H "Content-type: application/json" -d #-
With curl 7.82.0 and later
Starting with curl 7.82.0 you can do it even easier with the new --json option:
curl "<link>.json" | curl "<link2>" --json #-
I need to run a curl command on a container running in kubernetes cluster via PowerShell. Now, with curl, i need to pass various headers containing long token Strings. However, when i execute the command, the command string gets split in midway and terminal enters into newline mode from which I am not able to exit.
Below is the command.
curl -X GET http://sit-product-abcd-xyzx-adapter:8080/prdcopy/projects/PROJECT-NOVEMBER2020-eCom-SPORT_STYLE-3 -H "authorization: bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IlhSQVFGbGs3V0tNWnFzRm1ZUDcxaE55U3c4TSIsImtpZCI6IlhSQVFGbGs3V0tNWnFzRm1ZUDcxaE55U3c4TSJ9.eyJhdWQiOiJodHRwczovL2Rldi5hcGkuYWRpZGFzLmNvbS9jb3JwbWFya2V0L3ByZGNvcHkiLCJpc3MiOiJodHRwOi8vc3RzLXRlc3QuYWRpZGFzLWdyb3VwLmNvbS9hZGZzL3NlcnZpY2VzL3RydXN0IiwiaWF0IjoxNTYzOTUyOTI5LCJuYmYiOjE1NjM5NTI5MjksImV4cCI6MTU2Mzk1NjUyOSwic3ViIjoic3ZjX3BjYXBpIiwiZGlzdGluZ3Vpc2hlZG5hbWUiOiJDTj1zdmNfcGNhcGksT1U9U2VydmljZUFjY291bnRzLE9VPVVzZXJzLE9VPUVNQWRtaW5pc3RyYXRpb24sREM9ZW1lYSxEQz1h456bnQsREM9Yml6IiwiYXBwdHlwZSI6IkNvbmZpZGVudGlhbCIsImFwcGlkIjoiNTA4NzM2YTAtNzM5Mi00ODBkLTlmYWQtYWQ5NzUwMDI3ZjVhIiwiYXV0aG1ldGhvZCI6InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMDphYzpjbGFzc2VzOlBhc3N3b3JkUHJvdGVjdGVkVHJhbnNwb3J0IiwiYXV0aF90aW1lIjoiMjAxOS0wNy0yNFQwNzoyMjowOS43NTFaIiwidmVyIjoiMS4wIiwic2NwIjoidXNlcl9pbXBlcnNvbmF0aW9uIG9wZW5pZCJ9.kBrQO48rK_lkhDeZIQkW_If9lcYn5kERiif1VtlcXAPQ_j94KDGTfrmvF9f89EeyzExZSHFnCx0HyI8tvpeklEypWGchI4qG8V8z-AjTBrmKnX6mMSVLYaoh0TsLdeaFX-ByQ4TmyXzt5jje-CcS62w8P1J3aalVNhlTUp9e5rtP9qpttu2QmA482anQSsS6GN6ltJY9NyjfrW-ElZRrPXunIAf16jOjG0ehEUS8GpUJnc-wStJnF_zYuvnb-4m2GqzXqDHtpEvojg5N0Luq07z2mMpeEXbrGx-0fScjkSAsCJ8E-sFpbBYSXOCHfCslUPjM07kyzaZaa9tgWJGrGA" -H "cache-control: no-cache" -H "content-type: application/json" -H "project-id-type: API"
However, when i enter this command in power-shell after entering into the container, it looks like below.
PS R:\> kubectl exec -it sit-pcapi-order-event-consumer-b6f4c8797-m578d -- sh
/opt/app # curl -X GET http://sit-product-abcd-xyzx-adapter:8080/prdcopy/projects/PROJECT-NOVEMBER2020-eCom-SPORT_STYLE-
3 -H "authorization: bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IlhSQVFGbGs3V0tNWnFzRm1ZUDcxaE55U3c4TSIsImtpZCI6
IlhSQVFGbGs3V0tNWnFzRm1ZUDcxaE55U3c4TSJ9.eyJhdWQiOiJodHRwczovL2Rldi5hcGkuYWRpZGFzLmNvbS9jb3JwbWFya2V0L3ByZGNvcHkiLCJpc3M
iOiJodHRwOi8vc3RzLXRlc3QuYWRpZGFzLWdyb3VwLmNvbS9hZGZzL3NlcnZpY2VzL3RydXN0IiwiaWF0IjoxNTYzOTUyOTI5LCJuYmYiOjE1NjM5NTI5Mjk
sImV4cCI6MTU2Mzk1NjUyOSwic3ViIjoic3ZjX3BjYXBpIiwiZGlzdGluZ3Vpc2hlZG5hbWUiOiJDTj1zdmNfcGNhcGksT1U9U2VydmljZUFjY291bnRzLE9
VPVVzZXJzLE9VPUVNQWRtaW5pc3RyYXRpb24sREM9ZW1lYSxEQz1h456bnQsREM9Yml6IiwiYXBwdHlwZSI6IkNvbmZpZGVudGlhbCIsImFwcGlkIjoiNTA4
NzM2YTAtNzM5Mi00ODBkLTlmYWQtYWQ5NzUwMDI3ZjVhIiwiYXV0aG1ldGhvZCI6InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMDphYzpjbGFzc2VzOlBh
c3N3b3JkUHJvdGVjdGVkVHJhbnNwb3J0IiwiYXV0aF90aW1lIjoiMjAxOS0wNy0yNFQwNzoyMjowOS43NTFaIiwidmVyIjoiMS4wIiwic2NwIjoidXNlcl9p
bXBlcnNvbmF0aW9uIG9wZW5pZCJ9.kBrQO48rK_lkhDeZIQkW_If9lcYn5kERiif1VtlcXAPQ
>
>
>
After this, i need to close the terminal and re-login into the container and kill the sh process manually.
How can i exit this curl command in power-shell? How can i execute long curl commands? I tried powershell_ise, but in that, i am not able to execute kubectl exec command. After executing that command, the terminal remains stuck forever.
Maybe you can copy the token as file into the container/pod and then pass it to curl as file.
More or less like this:
# Copy file
kubectl cp /tmp/token namespace/sit-pcapi-order-event-consumer-b6f4c8797-m578d:/tmp/token
# Pass the token as file instead of literal
kubectl exec -it sit-pcapi-order-event-consumer-b6f4c8797-m578d -- sh /opt/app # curl -X GET http://.../ -H #header_file $URL
Regards
I'm using curl to create several classifications. I have written the json for the many classifications and they are in one folder. I would like to create all the classifications in one go. But using curl I can only create them one at a time. How could I make them in one request?
curl -u admin:admin -H "Content-Type: application/json" -X POST -d #pii.json http://127.0.0.1:21000/api/atlas/v2/types/typedefs
The curl manual for -d says 'Multiple files can also be specified'. How can I do this? All my attempts have failed.
Do I need a bash script instead? If so, could you help me - I'm not a coder and I'm struggling without an example!
Thanks in advance.
You probably don't want to use multiple -d with JSON data since curl concatenates multiple ones with a & in between. As described in the man page for -d/--data:
If any of these options is used more than once on the same command
line, the data pieces specified will be merged together with a
separating &-symbol. Thus, using '-d name=daniel -d skill=lousy' would
generate a post chunk that looks like 'name=daniel&skill=lousy'.
You can however easily and conveniently pass several files on stdin to let curl use them all in one go:
cat a.json b.json c.json | curl -d#- -u admin:admin -H "Content-Type: application/json" http://127.0.0.1:21000/api/atlas/v2/types/typedefs
(please note that -X POST has no place on a command line that uses -d)
I found the following to work in the end:
<fileToUpload.dat xargs -I % curl -X POST -T "{%}" -u admin:admin -H "Content-Type: application/json" http://127.0.0.1:21000/api/atlas/v2/types/typedefs
Where fileToUpload.dat contained a list of the .json files.
This seemed to work over Daniel's answer, probably due to the contents of the files. Hopefully this is useful to others if Daniel's solution doesn't work for them.
I needed to upload all the *.json files from a folder via curl and I made this little script.
nfiles=*.json
echo "Enter user:"
read user
echo "Enter password:"
read -s password
for file in $nfiles
do
echo -e "\n----$file----"
curl --user $user:$password -i -X POST "https://foo.bar/foo/bar" -H "Content-Type: application/json" -d "#$file"
done
Maybe fits your needs.