ansible-collections / community.vmware

Ansible Collection for VMware
GNU General Public License v3.0
344 stars 336 forks source link

vcenter_folder - parent folder not found #458

Open TimHarmon opened 3 years ago

TimHarmon commented 3 years ago
SUMMARY

When executing a vcenter_folder task using a long folder name as parent folder "nested" "Deployment_Environments/DP_LAB_H" ansible returns a parent folder does not exist. I have tried including the datacenter and VM and changing Deployment Environments to Deployment_Environments".

ISSUE TYPE
COMPONENT NAME

vcenter_folder

ANSIBLE VERSION
ansible 2.9.6
  config file = /home/timharmon/project/sgexpresspac3/ansible.cfg
  configured module search path = ['/home/timharmon/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0]
CONFIGURATION
DEFAULT_CALLBACK_WHITELIST(/home/timharmon/project/sgexpresspac3/ansible.cfg) = ['profile_tasks']
OS / ENVIRONMENT

esx 6.7, vcenter 6.7

STEPS TO REPRODUCE
non sensitive variables from site-vars
vsphere_parent_folder: "Deployment_Environments/DP_LAB_H_v455"
vsphere_folder_Name: "Express Build 2 - (SDS, CMP, LFV, BCC)"
---
  - hosts: all
    gather_facts: true
    connection: local
    vars_files:
      - site-vars.yml

    tasks:
      # Remove VM Guests
      # VMware 
      - name: Remove Virtual machine from environment
        vmware_guest:
          hostname: "{{ vsphere_host }}"
          username: "{{ vsphere_user }}"
          password: "{{ vsphere_password }}"
          validate_certs: no
          datacenter: "{{ vsphere_datacenter }}"
          cluster: "{{ vsphere_cluster }}"
          folder: "{{ vsphere_folder_Name }}"
          name: "{{ inventory_hostname }}"
          state: absent
          force: yes
        delegate_to: localhost

      - name: Remove VM folder
        vcenter_folder:
          hostname: "{{ vsphere_host }}"
          username: "{{ vsphere_user }}"
          password: "{{ vsphere_password }}"
          validate_certs: no
          datacenter: "{{ vsphere_datacenter }}"
          parent_folder: "{{ vsphere_parent_folder }}"
          folder_name: "{{ vsphere_folder_Name }}"
          folder_type: vm
          state: absent
        register: vm_folder_result
        delegate_to: localhost
EXPECTED RESULTS

folder removal

ACTUAL RESULTS

failure due to folder not present result

fatal: [<REDACTED>-> localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "datacenter": "<redacted>",
            "folder_name": "Express Build 2 - (<REDACTED>)",
            "folder_type": "vm",
            "hostname": "<Redacted>",
            "parent_folder": "Deployment_Environments/DP_LAB_H_v455",
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "port": 443,
            "proxy_host": null,
            "proxy_port": null,
            "state": "absent",
            "username": "<REDACTED>",
            "validate_certs": false
        }
    },
    "msg": "Parent folder Deployment_Environments/DP_LAB_H_v455 does not exist"
Akasurde commented 3 years ago

@TimHarmon Thanks for reporting this issue. Could you please paste the full path of parent folder?

I am not able to reproduce this error for path like

# govc find / 
...
/Asia-Datacenter1/vm/prod
/Asia-Datacenter1/vm/prod/tier1
/Asia-Datacenter1/vm/prod/tier1/tier2
/Asia-Datacenter1/vm/prod/tier1/tier2/tier3
...

and playbook


  - name: Delete tier3 folder
    vcenter_folder:
      hostname: '{{ vcenter_hostname }}'
      username: '{{ vcenter_username }}'
      password: '{{ vcenter_password }}'
      validate_certs: no
      datacenter: Asia-Datacenter1
      folder_name: tier3
      parent_folder: prod/tier1/tier2
      folder_type: vm
      state: absent
TimHarmon commented 3 years ago

@TimHarmon Thanks for reporting this issue. Could you please paste the full path of parent folder?

I am not able to reproduce this error for path like

# govc find / 
...
/Asia-Datacenter1/vm/prod
/Asia-Datacenter1/vm/prod/tier1
/Asia-Datacenter1/vm/prod/tier1/tier2
/Asia-Datacenter1/vm/prod/tier1/tier2/tier3
...

and playbook

  - name: Delete tier3 folder
    vcenter_folder:
      hostname: '{{ vcenter_hostname }}'
      username: '{{ vcenter_username }}'
      password: '{{ vcenter_password }}'
      validate_certs: no
      datacenter: Asia-Datacenter1
      folder_name: tier3
      parent_folder: prod/tier1/tier2
      folder_type: vm
      state: absent

@Akasurde, the full path I am using is /CISG-NJLAB/vm/Deployment_Environments/DP_LAB_H_v455/

Akasurde commented 3 years ago

@TimHarmon Are you using the latest version of vcenter_folder from the collection?

# ansible-galaxy collection list | grep vmware
community.vmware                1.3.0
...

~Also, I added a feature to identify parent folder using MoID - https://github.com/ansible-collections/community.vmware/pull/464~

~You can use the following playbook with PR #464~

Let me know.
Akasurde commented 3 years ago

@TimHarmon Could you please run the following playbook and let me know the output?

  - name: Get all folders
    community.vmware.vmware_folder_info:
      hostname: '{{ vcenter_hostname }}'
      username: '{{ vcenter_username }}'
      password: '{{ vcenter_password }}'
      validate_certs: no
      datacenter: '{{ datacenter_name }}'
    register: v

  - debug:
      msg: "{{ v.folder_info }}"
TimHarmon commented 3 years ago

will do as soon as I can.

On Wed, Nov 11, 2020 at 9:52 PM Abhijeet Kasurde notifications@github.com wrote:

@TimHarmon https://github.com/TimHarmon Could you please run the following playbook and let me know the output?

  • name: Get all folders community.vmware.vmware_folder_info: hostname: '{{ vcenter_hostname }}' username: '{{ vcenter_username }}' password: '{{ vcenter_password }}' validate_certs: no datacenter: '{{ datacenter_name }}' register: v

  • debug: msg: "{{ v.folder_info }}"

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ansible-collections/community.vmware/issues/458#issuecomment-725854836, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEAGCC46JFZVAFZ3ZZADDU3SPNZYNANCNFSM4S3TOSXA .

ansibullbot commented 3 years ago

cc @Tomorrow9 @goneri @lparkes @meerkampdvv @pgbidkar @warthog9 click here for bot help

laschalkh commented 3 years ago

Hi,

I've run into this today. Has any workaround been found?

Damianca commented 3 years ago

Hey team, Seems to be that parent_folder can't take several levels, it works for me using only one folder, ansible vmware community 1.12.0 and vcenter 6.7 and ansible 2.9.20. Thanks, Damian

fs30000 commented 8 months ago

I'm hitting on this bug as well. Can't create a simple folder.

- name: test
  hosts: localhost
  gather_facts: false
  vars_files: vars.yml
  tasks:
    - name: Main folder
      vcenter_folder:
        hostname: "{{ vcenter_host }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        validate_certs: false
        datacenter: "{{ vcenter_datacenter }}"
        parent_folder: "/datacenter1/vm/"
        folder_name: "TESTFOLDER"
        folder_type: vm
        state: present

For parent folder, i've tried: /datacenter1 datacenter1/ /datacenter1/ /datacenter1/vm /datacenter1/vm/ vm /vm vm/

Nothing works. Always fatal: [localhost]: FAILED! => {"changed": false, "msg": "Could not find folder FOO/whatever i choose

EDIT: The respective output from folder_info:

"vmFolders": { "moid": "group-v1002", "path": "/datacenter1/vm",

So the folder does exist.

SOLUTION: It does work if deleting the option "parent_folder" and mantaining only "folder_type: vm", then it creates the folder in root dir. On this case /datacenter1/vm/NEWFOLDER