#List volumes containing certain name conv
1 messages · Page 1 of 1 (latest)
You can pass patterns along as a parameter using the na_ontap_rest_info module:
- name: Gather volumes starting with DEV_ netapp.ontap.na_ontap_rest_info: <<: *login gather_subset: - storage/volumes parameters: name: "DEV_*" is_svm_root: false fields: - name register: volumes
said error using rest for version error 404 client error not found for ufl /ap/cluster?fields-version. error using REST version, status_code: 404
That was pointed at a svm. I pointed at the cluster and got this error:
Error using RESt for version, error HTTPSConnectionPool host IP port=443 max retries exceeded with url /api/cluster?fields=version (caused by newconnectionerror ('<urllib3.connection.VerifiedHTTPSConnection object at >; Failed to establish a new conenction Errno 111 connection refused' ERROR useing rest for version, status_code : None
What version of ONTAP are you using?
9.13.1
Could you try the following for me
curl --user <username>:<password> -kX GET https://<hostip>/api/cluster -H 'accept: application/hal+json'
You should get an Response back like the one below
carchi@carchi-mac-1 ~ $ curl --user <username>:<password> -kX GET https://<hostip>/api/cluster -H 'accept: application/hal+json'
{
"name": "ontap_cluster_1",
"uuid": "f6c9633d-9310-11ed-926e-005056b34578",
"version": {
"full": "NetApp Release Yellowdog__9.12.1: Thu Jan 12 13:14:09 UTC 2023",
"generation": 9,
"major": 12,
"minor": 1
},
curl (7) failed to connect to IP por t443 connection refused
OK so it look like the rest api on your system isn't enable or responding. By default it should be enable. you may want to reach out #1063542514780475493 and see how to renable it
I don't believe the getting started guide with Rest api https://docs.netapp.com/us-en/ontap-automation/get-started/ontap_automation_options.html talks about how to renable it but you way want to double check.
i made progress!
but im getting Error: Fields: [name], only one subset will be allowed
Was able to get the curl command working via help from the api forum, now getting this error
Error useing REST for version, error HTTPSConnectionPool (host= 'ip', port=443) Max retries exceeded with url: /api/cluster?fields=version (caused by Connecttimeouterror (<urllib3.connection.verifiedHTTPSConnection object at 1x7fe875eafa90>, connection to ip timed out (connect timeout = 60) error using REST cor version, status_code: none
So it looks like the REST API was waiting 60 second and hit the connection timeout. Not sure what causing your system to be really slow (or getting info on a lot of results) to hit the timeout limit
is there a way to extend that?
Making Progress, need to figure out how just to pull the name, right now its pulling more:
-
hosts: localhost
gather_facts: true
become: falsecollections:
- netapp.ontap
- netapp.Um_Info
tasks:
-
name: Gather Volumes starting with
netapp.ontap.na_ontap_rest_info:
hostname: ip
username: "user"
password: "password"
validate_certs: "false"
https: "true"
gather_subset:- volume_info
parameters:
name: "tkg_*"
fields: - 'name'
register: volumes
- volume_info
-
name: print volume list
debug:
msg: "{{ volumes }}"
OUTPUT:
{
"_links": {
"self": {
"href": "/api/storage/volumes/04c3f560-3626-11ee-9939-d039ea3ac245"
}
},
"name": "tkg_bravo_lab3_pvc_c2e22858_b7fe_4aa4_bdfb_38ee37ab84a9",
"uuid": "04c3f560-3626-11ee-9939-d039ea3ac245"
},
uuid, and _links is always returned by the rest api
If you are looking to just get the name you'll need to do something similar to what i have in this playbook that returning the SVM names.
hmmmmm, that screen shot didnt work
how would i pull the name of the volume out as a variable then to send to use else where?
interesting, screen shot worked on different machine. ill give that a try now, thank you
would i have to change ontap_info.svm_svms_records to something else?
Yes if you just print out {{ result }} you'll see the Json structure.
Volume i believe is storage_volume
that didnt seem to work
here is a print of result
task path: /runner/project/volume_list.yml:26
ok: [localhost] => {
"msg": {
"changed": false,
"failed": false,
"ontap_info": {
"storage/volumes": {
"links": {
"self": {
"href": "/api/storage/volumes?max_records=1024&fields=name&name=tkg%2A"
}
},
"num_records": 181,
"records": [
i dont see it listed
you need to add use_python_keys to your playbook
oh......other then the text line is there anything else i need?
then it would be results.ontap_info.storage_volumes.records
still getting this:
fatal: [localhost]: FAILED! => {
"msg": "'dict object' has no attribute 'storage_volume'"
volumes
task path: /runner/project/volume_list.yml:27
ok: [localhost] => (item={'uuid': '003c0b46-150b-11ee-a6bd-d039eaa7292b', 'name': 'tkg_itg_pvc_a0ed24d2_8f30_4000_b8a1_1f929db79f1a', '_links': {'self': {'href': '/api/storage/volumes/003c0b46-150b-11ee-a6bd-d039eaa7292b'}}}) => {
"msg": "tkg_itg_pvc_a0ed24d2_8f30_4000_b8a1_1f929db79f1a"
so is that what i want?
That the name you had here #1129076370652274759 message so yes
true. I guess i shold i have specified a little more. i need to get all the volumes in a variable so i use it in another task to register it in our backup solution
You can use that loop, in other tasks to loop through each name to do something
Like in another task in the same playbook find a way to just pull the name I want out
Yes you would use the a loop with the registered variable.
Ansible has a detailed page here on how loops work with registarted variables https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_loops.html