Fredouye / nutanix_ansible

Collection of Ansible roles to manage your Nutanix VMs
6 stars 4 forks source link

Failed to Create Snapshot #1

Closed jacklee5209 closed 2 years ago

jacklee5209 commented 2 years ago

Dear Fredouye, I hope you are doing well. I'm new to Ansible. I'm trying to use the roles to create/remove snapshots before/after the maintenance in Nutanix. But unfortunately, it was run to failed and given output as following. Not sure it's due to the API version issue or not as we are running Prism Central version pc.2021.9.0.4.

Following are Ansible version:

ansible [core 2.12.3] config file = None configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.10/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /usr/local/bin/ansible python version = 3.10.3 (main, Mar 21 2022, 04:38:32) [GCC 8.5.0 20210514 (Red Hat 8.5.0-4.0.2)] jinja version = 3.0.3 libyaml = True

Following are the error output:

TASK [/usr/share/ansible/nutanix_ansible/roles/vm_snapshot : Gets a list of all VMs] **** task path: /usr/share/ansible/nutanix_ansible/roles/vm_snapshot/tasks/main.yml:23

ESTABLISH LOCAL CONNECTION FOR USER: root EXEC /bin/sh -c 'echo ~root && sleep 0' EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1648444817.3845606-8882-198874861295131 `" && echo ansible-tmp-1648444817.3845606-8882-198874861295131="` echo /root/.ansible/tmp/ansible-tmp-1648444817.3845606-8882-198874861295131 `" ) && sleep 0' Using module file /usr/local/lib/python3.10/site-packages/ansible/modules/uri.py PUT /root/.ansible/tmp/ansible-local-8740l3c7lz_g/tmpnqid52zo TO /root/.ansible/tmp/ansible-tmp-1648444817.3845606-8882-198874861295131/AnsiballZ_uri.py EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1648444817.3845606-8882-198874861295131/ /root/.ansible/tmp/ansible-tmp-1648444817.3845606-8882-198874861295131/AnsiballZ_uri.py && sleep 0' EXEC /bin/sh -c '/usr/local/bin/python3.10 /root/.ansible/tmp/ansible-tmp-1648444817.3845606-8882-198874861295131/AnsiballZ_uri.py && sleep 0' EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1648444817.3845606-8882-198874861295131/ > /dev/null 2>&1 && sleep 0' The full traceback is: This action is not supported on Prism Central fatal: [SnapshotTargetHostname -> localhost]: FAILED! => { "cache_control": "no-store, no-cache, must-revalidate", "changed": false, "connection": "close", "content_security_policy": "default-src 'self' *.nutanix.com nutanix.com; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' 'unsafe-eval'; connect-src 'self' wss: https://downloads.frame.nutanix.com https://downloads.frame.nutanix.us; img-src 'self' blob: data:; frame-src 'self' https://*.nutanix.com blob: data:", "content_type": "application/json", "date": "Mon, 28 Mar 2022 05:20:24 GMT", "elapsed": 0, "expires": "0", "invocation": { "module_args": { "attributes": null, "body": null, "body_format": "raw", "ca_path": null, "client_cert": null, "client_key": null, "creates": null, "dest": null, "follow_redirects": "safe", "force": false, "force_basic_auth": false, "group": null, "headers": { "Cookie": "NTNX_SESSION_META=\"{\"uuid\":\"8a1d8b08-475b-477b-92ff-06f5662dba36\"}\";Path=/;Secure;Version=0;SameSite=Lax, JSESSIONID=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1c2VyX3Byb2ZpbGUiOiJ7XCJfcGVybWFuZW50XCI6dHJ1ZSxcInV1aWRcIjpcIjhhMWQ4YjA4LTQ3NWItNDc3Yi05MmZmLTA2ZjU2NjJkYmEzNlwiLFwidXNlcnR5cGVcIjpcIkxPQ0FMXCIsXCJhdXRoZW50aWNhdGVkXCI6dHJ1ZSxcImF1dGhvcml0aWVzXCI6W1wiUk9MRV9DTFVTVEVSX0FETUlOXCIsXCJST0xFX01VTFRJQ0xVU1RFUl9BRE1JTlwiLFwiUk9MRV9VU0VSX0FETUlOXCIsXCJST0xFX0NMVVNURVJfVklFV0VSXCJdLFwicHJpbmNpcGFsX25hbWVcIjpcImFkbWluXCIsXCJ1c2VyX3Byb2ZpbGVcIjp7XCJ1c2VybmFtZVwiOlwiYWRtaW5cIixcInBhc3N3b3JkXCI6bnVsbCxcImxvY2FsZVwiOlwiZW4tVVNcIixcInJlZ2lvblwiOlwiZW4tVVNcIixcImZpcnN0X25hbWVcIjpudWxsLFwibWlkZGxlX2luaXRpYWxcIjpudWxsLFwibGFzdF9uYW1lXCI6bnVsbCxcImVtYWlsX2lkXCI6bnVsbH0sXCJvcmlnX3Rva2VuX2lzc190aW1lXCI6MTY0ODQ0NDgyMH0iLCJqdGkiOiI5MTE4ZWE3NC1lMDJmLTRhZWUtYjllNC04ZTUwYmFmYzg1YWQiLCJpc3MiOiJBdGhlbmEiLCJpYXQiOjE2NDg0NDQ4MjEsImV4cCI6MTY0ODQ0NTcyMX0.WC8MFm-WWh8Hg-SOXAwUBI6Un0zWqmMFHLCKPIMeHT2MIPtFECJsMLbjE4xs3OyxVjPO7Y-ez1tLdEFX_8H5Tgg6z06vE8yrPxhOEQYOtud6utgzNjmEhKkh1FppFJi-tIMSyUNBRv-bC7hHC1oX-Y16xCy8VnYBUarLU1OpXhmbnhVZmyU_p557agQJ8E9PC936HG0qeMKn6Q4_Bz57ChzUgQz8iAjpVQpvLNP4-IAfs1VY28ZJhMheaWy1nCRdIO6ixjWSO7M3F_Fi0aIOFgmF87rb21a2bOTPSawzm6uQxt5Smpqxp16zmNPgLkijUbOjRs7gbRTYYJsgkd_ehw;Max-Age=900;Path=/;Secure;Version=0;SameSite=Lax" }, "http_agent": "ansible-httpget", "method": "GET", "mode": null, "owner": null, "remote_src": false, "removes": null, "return_content": false, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": null, "status_code": [ 200 ], "timeout": 30, "unix_socket": null, "unredirected_headers": [], "unsafe_writes": false, "url": "https://10.xx.xxx.xxx:9440/PrismGateway/services/rest/v2.0/vms/list", "url_password": null, "url_username": null, "use_gssapi": false, "use_proxy": true, "validate_certs": false } }, "json": { "detailed_message": "This action is not supported on Prism Central", "error_code": { "code": 1101, "help_url": "http://my.nutanix.com" }, "message": "This action is not supported on Prism Central" }, "msg": "Status code was 412 and not [200]: HTTP Error 412: PRECONDITION FAILED", "pragma": "no-cache", "redirected": false, "server": "envoy", "status": 412, "strict_transport_security": "max-age=8640000:includeSubdomains", "transfer_encoding": "chunked", "url": "https://10.xx.xxx.xxx:9440/PrismGateway/services/rest/v2.0/vms/list", "x_content_type_options": "nosniff", "x_dns_prefetch_control": "off", "x_envoy_upstream_service_time": "8", "x_frame_options": "SAMEORIGIN", "x_ntnx_env": "pc", "x_ntnx_product": "pc.2021.9.0.4", "x_permitted_cross_domain_policies": "master-only", "x_webkit_csp": "default-src 'self' *.nutanix.com nutanix.com; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' 'unsafe-eval'; connect-src 'self' wss: https://downloads.frame.nutanix.com https://downloads.frame.nutanix.us; img-src 'self' blob: data:; frame-src 'self' https://*.nutanix.com blob: data:", "x_xss_protection": "1; mode=block"
Fredouye commented 2 years ago

Hi jacklee5209

thanks for the report.

Sorry for this, I was wrong when I wrote that this role could be used with a Prisme Central or a Prisme Element...

Snapshots are only referenced with API v2 : https://www.nutanix.dev/reference/prism_element/v2/ And API v2 calls can only be used with Prisme Element, whereas API v3 calls can be used with both Prisme.

Until Nutanix releases an API v3 call for snapshots, I'll add a comment in this role's documentation.

jacklee5209 commented 2 years ago

Hi Fredouye, Thanks for your quick response. I manage to create and remove snapshot on Prism Element with the role now. This is awesome!!! But I have a question...

Would you mind to share the example of loops? We have multiple clusters in the environment. its not handy if we keep changing the prism_url to look for the VM that we wish to create snapshot. I had gone through few KBs of Ansible but still no clue how to loops the clusters.

Sorry for any inconvenience cause.

Fredouye commented 2 years ago

Hi

this role can access multiple Nutanix clusters, this variable (located in the defaults directory) relies on another variable :

api_url_v2: "https://{{ prism_url }}:9440/PrismGateway/services/rest/v2.0"

IMHO you just have to declare the following variables in your Ansible inventories. For example, if you're not using group_vars :

[PROD:vars]
prism_url: 192.168.3.245
prism_user: admin-prod
prism_password: xxxxxxx

[PROD]
my_prod_vm_1
my_prod_vm_2

[DEV:vars]
prism_url: 192.168.2.1
prism_user: admin-dev
prism_password: xxxxxxx

[DEV]
my_dev_vm_1
my_dev_vm_2

You could even declare these variables on a host level, but I guess it would be less efficient.

jacklee5209 commented 2 years ago

Hi, Thanks for your opinions. Just wanted to know whether can put a condition check before the task "Takes a snapshot" execute? This is to check the vms name in the inventory whether match with the list of vms that the task "Gets a list of all VMs" retrieved. If its not , stop/skip the remaining tasks instead of throwing error. This will be helpful if we state the looping in the playbook and no harm to those user who are running in single node. Hope this idea is works and sorry for bothering you.

jacklee5209 commented 2 years ago

Thanks buddy. I manage to overcome the issue by adding the conditionals "when" on the rest of the tasks in the role. I created a loop in playbook with Prism Element hostname, so the role will loop the PE host until it found the VMs that we stated in the inventory. This will be more handy as we no need to separate VMs into difference group and giving them different group vars when they are login with the same credential.