2018-02-05 18:01:58 +01:00
|
|
|
# Test code for the vcenter_folder module.
|
|
|
|
# Copyright: (c) 2018, Abhijeet Kasurde <akasurde@redhat.com>
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
2018-10-19 17:45:58 +02:00
|
|
|
- name: Create all types of folder in check mode
|
|
|
|
vcenter_folder:
|
2019-04-24 19:36:19 +02:00
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
2018-10-19 17:45:58 +02:00
|
|
|
validate_certs: no
|
|
|
|
datacenter: "{{ dc1 }}"
|
|
|
|
folder_name: "{{ item }}_folder"
|
|
|
|
folder_type: "{{ item }}"
|
|
|
|
state: present
|
|
|
|
register: all_folder_results
|
|
|
|
with_items:
|
|
|
|
- vm
|
|
|
|
- host
|
|
|
|
- datastore
|
|
|
|
- network
|
|
|
|
check_mode: yes
|
|
|
|
|
2019-04-24 19:36:19 +02:00
|
|
|
- debug:
|
|
|
|
msg: "{{ all_folder_results }}"
|
2018-10-19 17:45:58 +02:00
|
|
|
|
|
|
|
- name: ensure everything for {{ dc1 }}
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- all_folder_results.changed
|
|
|
|
|
2018-02-05 18:01:58 +01:00
|
|
|
- name: Create all types of folder
|
|
|
|
vcenter_folder:
|
2019-04-24 19:36:19 +02:00
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
2018-02-05 18:01:58 +01:00
|
|
|
validate_certs: no
|
|
|
|
datacenter: "{{ dc1 }}"
|
|
|
|
folder_name: "{{ item }}_folder"
|
|
|
|
folder_type: "{{ item }}"
|
|
|
|
state: present
|
|
|
|
register: all_folder_results
|
|
|
|
with_items:
|
|
|
|
- vm
|
|
|
|
- host
|
|
|
|
- datastore
|
|
|
|
- network
|
|
|
|
|
2019-04-24 19:36:19 +02:00
|
|
|
- debug:
|
|
|
|
msg: "{{ all_folder_results }}"
|
2018-02-05 18:01:58 +01:00
|
|
|
|
2018-10-19 17:45:58 +02:00
|
|
|
- name: ensure everything for {{ dc1 }}
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- all_folder_results.changed
|
|
|
|
|
|
|
|
- name: Create all types of sub folder in check mode
|
|
|
|
vcenter_folder:
|
2019-04-24 19:36:19 +02:00
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
2018-10-19 17:45:58 +02:00
|
|
|
validate_certs: no
|
|
|
|
datacenter: "{{ dc1 }}"
|
|
|
|
folder_name: "sub_{{ item }}_folder"
|
|
|
|
parent_folder: 'vm_folder'
|
|
|
|
state: present
|
|
|
|
register: all_folder_results
|
|
|
|
with_items:
|
|
|
|
- vm
|
|
|
|
- host
|
|
|
|
- datastore
|
|
|
|
- network
|
|
|
|
check_mode: yes
|
|
|
|
|
2019-04-24 19:36:19 +02:00
|
|
|
- debug:
|
|
|
|
msg: "{{ all_folder_results }}"
|
2018-10-19 17:45:58 +02:00
|
|
|
|
2018-02-05 18:01:58 +01:00
|
|
|
- name: ensure everything for {{ dc1 }}
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- all_folder_results.changed
|
|
|
|
|
|
|
|
- name: Create all types of sub folder
|
|
|
|
vcenter_folder:
|
2019-04-24 19:36:19 +02:00
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
2018-02-05 18:01:58 +01:00
|
|
|
validate_certs: no
|
|
|
|
datacenter: "{{ dc1 }}"
|
|
|
|
folder_name: "sub_{{ item }}_folder"
|
|
|
|
parent_folder: 'vm_folder'
|
|
|
|
state: present
|
|
|
|
register: all_folder_results
|
|
|
|
with_items:
|
|
|
|
- vm
|
|
|
|
- host
|
|
|
|
- datastore
|
|
|
|
- network
|
2018-10-19 17:45:58 +02:00
|
|
|
|
2018-07-30 07:41:42 +02:00
|
|
|
- name: Recreate all types of sub folder
|
|
|
|
vcenter_folder:
|
2019-04-24 19:36:19 +02:00
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
2018-07-30 07:41:42 +02:00
|
|
|
validate_certs: no
|
|
|
|
datacenter: "{{ dc1 }}"
|
|
|
|
folder_name: "sub_{{ item }}_folder"
|
|
|
|
parent_folder: 'vm_folder'
|
|
|
|
state: present
|
|
|
|
register: recreate_folders
|
|
|
|
with_items:
|
|
|
|
- vm
|
|
|
|
- host
|
|
|
|
- datastore
|
|
|
|
- network
|
2018-02-05 18:01:58 +01:00
|
|
|
|
2019-11-22 15:25:42 +01:00
|
|
|
- name: Create a 3rd level of directory
|
|
|
|
vcenter_folder:
|
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
|
|
|
validate_certs: no
|
|
|
|
datacenter: "{{ dc1 }}"
|
|
|
|
folder_name: yet_another_level
|
|
|
|
parent_folder: vm_folder/sub_vm_folder
|
|
|
|
state: present
|
|
|
|
register: yet_another_level
|
|
|
|
- debug: var=yet_another_level
|
|
|
|
|
|
|
|
|
2019-04-24 19:36:19 +02:00
|
|
|
- debug:
|
|
|
|
msg: "{{ all_folder_results }}"
|
2018-02-05 18:01:58 +01:00
|
|
|
|
|
|
|
- name: ensure everything for {{ dc1 }}
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- all_folder_results.changed
|
2018-07-30 07:41:42 +02:00
|
|
|
- not recreate_folders.changed
|
2018-02-05 18:01:58 +01:00
|
|
|
|
2019-04-24 19:36:19 +02:00
|
|
|
## Testcase: Delete all types of folder
|
2018-10-19 17:45:58 +02:00
|
|
|
#
|
|
|
|
# Doesn't work with vcsim. Looks like UnregisterAndDestroy isn't supported.
|
2019-04-24 19:36:19 +02:00
|
|
|
- when: vcsim is not defined
|
|
|
|
block:
|
|
|
|
- name: Delete all types of folder
|
|
|
|
vcenter_folder:
|
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
|
|
|
validate_certs: no
|
|
|
|
datacenter: "{{ dc1 }}"
|
|
|
|
folder_name: "{{ item }}_folder"
|
|
|
|
folder_type: "{{ item }}"
|
|
|
|
state: absent
|
|
|
|
register: all_folder_results
|
|
|
|
with_items:
|
|
|
|
- vm
|
|
|
|
- host
|
|
|
|
- datastore
|
|
|
|
- network
|
|
|
|
|
|
|
|
- debug: msg="{{ all_folder_results }}"
|
|
|
|
|
|
|
|
- name: ensure everything for {{ dc1 }}
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- all_folder_results.changed
|
|
|
|
|
|
|
|
- name: Delete all types of folder again
|
|
|
|
vcenter_folder:
|
|
|
|
hostname: "{{ vcenter_hostname }}"
|
|
|
|
username: "{{ vcenter_username }}"
|
|
|
|
password: "{{ vcenter_password }}"
|
|
|
|
validate_certs: no
|
|
|
|
datacenter: "{{ dc1 }}"
|
|
|
|
folder_name: "{{ item }}_folder"
|
|
|
|
folder_type: "{{ item }}"
|
|
|
|
state: absent
|
|
|
|
register: all_folder_results
|
|
|
|
with_items:
|
|
|
|
- vm
|
|
|
|
- host
|
|
|
|
- datastore
|
|
|
|
- network
|
|
|
|
|
|
|
|
- debug: msg="{{ all_folder_results }}"
|
|
|
|
|
|
|
|
- name: ensure everything for {{ dc1 }}
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- not all_folder_results.changed
|