Hello, all. I'm working with VMware modules in removing snapshots across all vCenter folders. In order for this to work, I first have to get the folders in which the virtual machines live. Here's the playbook:
*---- hosts: all become: false gather_facts: false vars_prompt: - name: "vcenter_username" prompt: "Enter your Vcenter username" private: no - name: "vcenter_password" prompt: "Enter your VMware password" private: yes vars: vcenter_hostname: vcenter1.mycompany.com vcenter_datacenter: First Datacenter tasks: - name: Find virtual machine's folder name vmware_guest_find: hostname: "{{ vcenter_hostname }}" username: "{{ vcenter_username }}" password: "{{ vcenter_password }}" name: "{{ inventory_hostname }}" validate_certs: False delegate_to: localhost ignore_errors: true register: vm_facts tags:* * - folder - name: Show folders ansible.builtin.debug: msg: "{{ vm_facts.folders }}" tags: - folder - name: Remove all snapshots of a VM community.vmware.vmware_guest_snapshot: hostname: "{{ vcenter_hostname }}" username: "{{ vcenter_username }}" password: "{{ vcenter_password }}" datacenter: "{{ vcenter_datacenter }}" folder: "{{ vm_facts.folders | regex_replace('(\\[)|(\\])', '') }}" name: "{{ inventory_hostname }}" state: remove_all validate_certs: False delegate_to: localhost* Previous to my having employed regex_replace, this is the output I'd get, e.g., for a vm's folder: *"['/First Datacenter/vm/Prod-SRM']"* The problem with that is *['* and *']*. They can't be part pf the folder name. After employing regex-replace, the output is: *" '/Bedford Datacenter/vm/Bedford-Prod-SRM' "* Try as I may, I've not been able to find a way to also remove the single quotes (the double quotes can remain). I've tried appending to the regex_replace, but every piece of code i've used has failed. *regex_replace('(\\[)|(\\])'|(addlcodehere), '') }}* Your kinf assistance requested. -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/34393455-5021-4342-89b4-de276d68ccd9n%40googlegroups.com.