Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vmware.vcenter_folder: does not create folder at the root when a 'subfolder' with the same name already exists #2054

Open
remkolodder opened this issue Apr 24, 2024 · 3 comments

Comments

@remkolodder
Copy link

SUMMARY

Initially I developed code for my employer, to create a list of folders and subfolders using community.vmware.vcenter_folder. The default version that gets installed on my test instance was 1.7.0 and that created the folders on the place I expect them to be created.

However, for work we use version 4.3.0, and there the same folder is not created as rootfolder, when a subfolder with the same name already exists.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.vmware.vcenter_folder

ANSIBLE VERSION
$ ansible --version
ansible [core 2.16.2]
  config file = None
  configured module search path = ['/home/remko/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.10/dist-packages/ansible
  ansible collection location = /home/remko/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.1.3
  libyaml = True

COLLECTION VERSION
# /home/remko/.ansible/collections/ansible_collections
Collection       Version
---------------- -------
community.vmware 1.7.0

# /usr/lib/python3/dist-packages/ansible_collections
Collection       Version
---------------- -------
community.vmware 1.7.0
CONFIGURATION
$ ansible-config dump --only-changed
CONFIG_FILE() = None
OS / ENVIRONMENT

The error can be reproduced on multiple different versions on different hardware. The version used is 1.7.0 which works and 4.3.0 that does not work.

STEPS TO REPRODUCE

run the below playbook and see the output of the task using v 4.3.0:

/home/remko/.ansible/collections/ansible_collections

Collection Version


community.vmware 4.3.0

/usr/lib/python3/dist-packages/ansible_collections

Collection Version


community.vmware 1.7.0

ansible-playbook -vvvv ./playbookfile.yaml

---
- name: Build everything
  hosts: localhost
  gather_facts: false
  vars_files:
    - credentials.yaml
  vars:
    folder_structure:
      test1:
      test2:
      this_folder_should_be_on_root:

  tasks:
    - name: Create rootfolder
      community.vmware.vcenter_folder:
        hostname: "{{ vcenter_hostname }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        validate_certs: false
        datacenter_name: "vdc1"
        folder_name: "{{ item }}"
        folder_type: "vm"
        state: present
      register: vm_rootfolder_create
      delegate_to: localhost
      loop: "{{ folder_structure.keys() }}"
EXPECTED RESULTS

TASK [Create rootfolder] ********************************************************************************************************************************************************************************************
task path: /home/remko/workspace/git/scripts/ansible/projects/folders_demo/local_build_folders.yaml:14
Read vars_file 'credentials.yaml'
ESTABLISH LOCAL CONNECTION FOR USER: remko
EXEC /bin/sh -c 'echo ~remko && sleep 0'
EXEC /bin/sh -c '( umask 77 && mkdir -p "echo /home/remko/.ansible/tmp"&& mkdir "echo /home/remko/.ansible/tmp/ansible-tmp-1713884307.3059566-3273653-280408203908701" && echo ansible-tmp-1713884307.3059566-3273653-280408203908701="echo /home/remko/.ansible/tmp/ansible-tmp-1713884307.3059566-3273653-280408203908701" ) && sleep 0'
Using module file /home/remko/.ansible/collections/ansible_collections/community/vmware/plugins/modules/vcenter_folder.py
PUT /home/remko/.ansible/tmp/ansible-local-3273627121gn612/tmpcft70qyt TO /home/remko/.ansible/tmp/ansible-tmp-1713884307.3059566-3273653-280408203908701/AnsiballZ_vcenter_folder.py
EXEC /bin/sh -c 'chmod u+x /home/remko/.ansible/tmp/ansible-tmp-1713884307.3059566-3273653-280408203908701/ /home/remko/.ansible/tmp/ansible-tmp-1713884307.3059566-3273653-280408203908701/AnsiballZ_vcenter_folder.py && sleep 0'
EXEC /bin/sh -c '/usr/bin/python3 /home/remko/.ansible/tmp/ansible-tmp-1713884307.3059566-3273653-280408203908701/AnsiballZ_vcenter_folder.py && sleep 0'
EXEC /bin/sh -c 'rm -f -r /home/remko/.ansible/tmp/ansible-tmp-1713884307.3059566-3273653-280408203908701/ > /dev/null 2>&1 && sleep 0'
ok: [localhost] => (item=test1) => {
"ansible_loop_var": "item",
"changed": false,
"invocation": {
"module_args": {
"datacenter": "vdc1",
"datacenter_name": "vdc1",
"folder_name": "test1",
"folder_type": "vm",
"hostname": "vcenter.lan.elvandar.org",
"parent_folder": null,
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"port": 443,
"proxy_host": null,
"proxy_port": null,
"state": "present",
"username": "administrator@vsphere.local",
"validate_certs": false
}
},
"item": "test1",
"result": {
"msg": "Folder test1 already exists",
"path": "/vdc1/vm/test1"
}
}
Read vars_file 'credentials.yaml'
EXEC /bin/sh -c 'echo ~remko && sleep 0'
EXEC /bin/sh -c '( umask 77 && mkdir -p "echo /home/remko/.ansible/tmp"&& mkdir "echo /home/remko/.ansible/tmp/ansible-tmp-1713884307.7591896-3273653-205672076350747" && echo ansible-tmp-1713884307.7591896-3273653-205672076350747="echo /home/remko/.ansible/tmp/ansible-tmp-1713884307.7591896-3273653-205672076350747" ) && sleep 0'
Using module file /home/remko/.ansible/collections/ansible_collections/community/vmware/plugins/modules/vcenter_folder.py
PUT /home/remko/.ansible/tmp/ansible-local-3273627121gn612/tmpt4vo938l TO /home/remko/.ansible/tmp/ansible-tmp-1713884307.7591896-3273653-205672076350747/AnsiballZ_vcenter_folder.py
EXEC /bin/sh -c 'chmod u+x /home/remko/.ansible/tmp/ansible-tmp-1713884307.7591896-3273653-205672076350747/ /home/remko/.ansible/tmp/ansible-tmp-1713884307.7591896-3273653-205672076350747/AnsiballZ_vcenter_folder.py && sleep 0'
EXEC /bin/sh -c '/usr/bin/python3 /home/remko/.ansible/tmp/ansible-tmp-1713884307.7591896-3273653-205672076350747/AnsiballZ_vcenter_folder.py && sleep 0'
EXEC /bin/sh -c 'rm -f -r /home/remko/.ansible/tmp/ansible-tmp-1713884307.7591896-3273653-205672076350747/ > /dev/null 2>&1 && sleep 0'
ok: [localhost] => (item=test2) => {
"ansible_loop_var": "item",
"changed": false,
"invocation": {
"module_args": {
"datacenter": "vdc1",
"datacenter_name": "vdc1",
"folder_name": "test2",
"folder_type": "vm",
"hostname": "vcenter.lan.elvandar.org",
"parent_folder": null,
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"port": 443,
"proxy_host": null,
"proxy_port": null,
"state": "present",
"username": "administrator@vsphere.local",
"validate_certs": false
}
},
"item": "test2",
"result": {
"msg": "Folder test2 already exists",
"path": "/vdc1/vm/test2"
}
}
Read vars_file 'credentials.yaml'
EXEC /bin/sh -c 'echo ~remko && sleep 0'
EXEC /bin/sh -c '( umask 77 && mkdir -p "echo /home/remko/.ansible/tmp"&& mkdir "echo /home/remko/.ansible/tmp/ansible-tmp-1713884308.0468104-3273653-57446805593036" && echo ansible-tmp-1713884308.0468104-3273653-57446805593036="echo /home/remko/.ansible/tmp/ansible-tmp-1713884308.0468104-3273653-57446805593036" ) && sleep 0'
Using module file /home/remko/.ansible/collections/ansible_collections/community/vmware/plugins/modules/vcenter_folder.py
PUT /home/remko/.ansible/tmp/ansible-local-3273627121gn612/tmpkj8ygit0 TO /home/remko/.ansible/tmp/ansible-tmp-1713884308.0468104-3273653-57446805593036/AnsiballZ_vcenter_folder.py
EXEC /bin/sh -c 'chmod u+x /home/remko/.ansible/tmp/ansible-tmp-1713884308.0468104-3273653-57446805593036/ /home/remko/.ansible/tmp/ansible-tmp-1713884308.0468104-3273653-57446805593036/AnsiballZ_vcenter_folder.py && sleep 0'
EXEC /bin/sh -c '/usr/bin/python3 /home/remko/.ansible/tmp/ansible-tmp-1713884308.0468104-3273653-57446805593036/AnsiballZ_vcenter_folder.py && sleep 0'
EXEC /bin/sh -c 'rm -f -r /home/remko/.ansible/tmp/ansible-tmp-1713884308.0468104-3273653-57446805593036/ > /dev/null 2>&1 && sleep 0'
changed: [localhost] => (item=this_folder_should_be_on_root) => {
"ansible_loop_var": "item",
"changed": true,
"invocation": {
"module_args": {
"datacenter": "vdc1",
"datacenter_name": "vdc1",
"folder_name": "this_folder_should_be_on_root",
"folder_type": "vm",
"hostname": "vcenter.lan.elvandar.org",
"parent_folder": null,
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"port": 443,
"proxy_host": null,
"proxy_port": null,
"state": "present",
"username": "administrator@vsphere.local",
"validate_certs": false
}
},
"item": "this_folder_should_be_on_root",
"result": {
"msg": "Folder 'this_folder_should_be_on_root' of type 'vm' created successfully.",
"path": "/vdc1/vm/this_folder_should_be_on_root"
}
}

ACTUAL RESULTS

Instead of adding the folder to the rootlevel (there is no parent specified), the command now sees there is a subfolder somewhere with the same name and does not create it anymore. While I can understand that potentially for subfolders (how to track them, and where), it might be easier to use the moid for the folder and use that as either root (datacenter-1001) or subfolder location, instead of making assumptions that in this case are very much incorrect.

TASK [Create rootfolder] ********************************************************************************************************************************************************************************************
task path: /home/remko/workspace/git/scripts/ansible/projects/folders_demo/local_build_folders.yaml:14
Read vars_file 'credentials.yaml'
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: remko
<localhost> EXEC /bin/sh -c 'echo ~remko && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/remko/.ansible/tmp `"&& mkdir "` echo /home/remko/.ansible/tmp/ansible-tmp-1713938390.659332-3795044-134873189072766 `" && echo ansible-tmp-1713938390.659332-3795044-134873189072766="` echo /home/remko/.ansible/tmp/ansible-tmp-1713938390.659332-3795044-134873189072766 `" ) && sleep 0'
Using module file /home/remko/.ansible/collections/ansible_collections/community/vmware/plugins/modules/vcenter_folder.py
<localhost> PUT /home/remko/.ansible/tmp/ansible-local-37950404cn2myn1/tmp8kl5sb_4 TO /home/remko/.ansible/tmp/ansible-tmp-1713938390.659332-3795044-134873189072766/AnsiballZ_vcenter_folder.py
<localhost> EXEC /bin/sh -c 'chmod u+x /home/remko/.ansible/tmp/ansible-tmp-1713938390.659332-3795044-134873189072766/ /home/remko/.ansible/tmp/ansible-tmp-1713938390.659332-3795044-134873189072766/AnsiballZ_vcenter_folder.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python3 /home/remko/.ansible/tmp/ansible-tmp-1713938390.659332-3795044-134873189072766/AnsiballZ_vcenter_folder.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /home/remko/.ansible/tmp/ansible-tmp-1713938390.659332-3795044-134873189072766/ > /dev/null 2>&1 && sleep 0'
ok: [localhost] => (item=test1) => {
    "ansible_loop_var": "item",
    "changed": false,
    "invocation": {
        "module_args": {
            "datacenter": "vdc1",
            "datacenter_name": "vdc1",
            "folder_name": "test1",
            "folder_type": "vm",
            "hostname": "vcenter.lan.elvandar.org",
            "parent_folder": null,
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "port": 443,
            "proxy_host": null,
            "proxy_port": null,
            "state": "present",
            "username": "administrator@vsphere.local",
            "validate_certs": false
        }
    },
    "item": "test1",
    "result": {
        "msg": "Folder test1 already exists",
        "path": "/vdc1/vm/test1"
    }
}
Read vars_file 'credentials.yaml'
<localhost> EXEC /bin/sh -c 'echo ~remko && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/remko/.ansible/tmp `"&& mkdir "` echo /home/remko/.ansible/tmp/ansible-tmp-1713938391.0438638-3795044-173160103186654 `" && echo ansible-tmp-1713938391.0438638-3795044-173160103186654="` echo /home/remko/.ansible/tmp/ansible-tmp-1713938391.0438638-3795044-173160103186654 `" ) && sleep 0'
Using module file /home/remko/.ansible/collections/ansible_collections/community/vmware/plugins/modules/vcenter_folder.py
<localhost> PUT /home/remko/.ansible/tmp/ansible-local-37950404cn2myn1/tmpigwbbrco TO /home/remko/.ansible/tmp/ansible-tmp-1713938391.0438638-3795044-173160103186654/AnsiballZ_vcenter_folder.py
<localhost> EXEC /bin/sh -c 'chmod u+x /home/remko/.ansible/tmp/ansible-tmp-1713938391.0438638-3795044-173160103186654/ /home/remko/.ansible/tmp/ansible-tmp-1713938391.0438638-3795044-173160103186654/AnsiballZ_vcenter_folder.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python3 /home/remko/.ansible/tmp/ansible-tmp-1713938391.0438638-3795044-173160103186654/AnsiballZ_vcenter_folder.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /home/remko/.ansible/tmp/ansible-tmp-1713938391.0438638-3795044-173160103186654/ > /dev/null 2>&1 && sleep 0'
ok: [localhost] => (item=test2) => {
    "ansible_loop_var": "item",
    "changed": false,
    "invocation": {
        "module_args": {
            "datacenter": "vdc1",
            "datacenter_name": "vdc1",
            "folder_name": "test2",
            "folder_type": "vm",
            "hostname": "vcenter.lan.elvandar.org",
            "parent_folder": null,
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "port": 443,
            "proxy_host": null,
            "proxy_port": null,
            "state": "present",
            "username": "administrator@vsphere.local",
            "validate_certs": false
        }
    },
    "item": "test2",
    "result": {
        "msg": "Folder test2 already exists",
        "path": "/vdc1/vm/test2"
    }
}
Read vars_file 'credentials.yaml'
<localhost> EXEC /bin/sh -c 'echo ~remko && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/remko/.ansible/tmp `"&& mkdir "` echo /home/remko/.ansible/tmp/ansible-tmp-1713938391.292563-3795044-42446442633140 `" && echo ansible-tmp-1713938391.292563-3795044-42446442633140="` echo /home/remko/.ansible/tmp/ansible-tmp-1713938391.292563-3795044-42446442633140 `" ) && sleep 0'
Using module file /home/remko/.ansible/collections/ansible_collections/community/vmware/plugins/modules/vcenter_folder.py
<localhost> PUT /home/remko/.ansible/tmp/ansible-local-37950404cn2myn1/tmprqq67h97 TO /home/remko/.ansible/tmp/ansible-tmp-1713938391.292563-3795044-42446442633140/AnsiballZ_vcenter_folder.py
<localhost> EXEC /bin/sh -c 'chmod u+x /home/remko/.ansible/tmp/ansible-tmp-1713938391.292563-3795044-42446442633140/ /home/remko/.ansible/tmp/ansible-tmp-1713938391.292563-3795044-42446442633140/AnsiballZ_vcenter_folder.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python3 /home/remko/.ansible/tmp/ansible-tmp-1713938391.292563-3795044-42446442633140/AnsiballZ_vcenter_folder.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /home/remko/.ansible/tmp/ansible-tmp-1713938391.292563-3795044-42446442633140/ > /dev/null 2>&1 && sleep 0'
ok: [localhost] => (item=this_folder_should_be_on_root) => {
    "ansible_loop_var": "item",
    "changed": false,
    "invocation": {
        "module_args": {
            "datacenter": "vdc1",
            "datacenter_name": "vdc1",
            "folder_name": "this_folder_should_be_on_root",
            "folder_type": "vm",
            "hostname": "vcenter.lan.elvandar.org",
            "parent_folder": null,
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "port": 443,
            "proxy_host": null,
            "proxy_port": null,
            "state": "present",
            "username": "administrator@vsphere.local",
            "validate_certs": false
        }
    },
    "item": "this_folder_should_be_on_root",
    "result": {
        "msg": "Folder this_folder_should_be_on_root already exists",
        "path": "/vdc1/vm/testfolder/this_folder_should_be_on_root"
    }
}
@remkolodder
Copy link
Author

remkolodder commented Apr 24, 2024

My colleague reported that

Screenshot 2024-04-24 at 09 07 40

inside vcenter_folder.py, is the only thing that changed between the versions and makes it likely the cause of the issue.
If i remove that, it will create the folder as expected.

I am ofcourse willing to create a diff for this and a pull request, but is it something that you did on purpose and what is the reasoning behind it?

@mariolenz
Copy link
Collaborator

It looks like this has been implemented in #1113 in order to fix #1112. At least, that's what I've found out. I don't know more about it.

@remkolodder
Copy link
Author

Apparently indeed, i can also understand why, because on subfolders you might get conflicts, and especially because the abstraction is 'parent folder' together with 'folder name', which can conflict if you have test1/parent_folder/folder_name and test2/parent_folder/folder_name, because which one is the right one? The one under test1 or test2?

I think the empty parent_folder though, is a special case where we say it's on the rootlevel of things, and either exists at rootlevel or not, which is different for folders with a parent folder as mentioned before.

The moid is ofcourse more unique but might make it more tricky to write an abstraction in config:

folders:
a:
subfolder_b
c:
subfolder_d

etc will not work with moid, you need to have "key-values" and able to calculate the id of c somewhere and store that so that subfolder_d will be created on the right entity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants