summaryrefslogtreecommitdiff
path: root/test/integration/targets/vmware_guest_powerstate/tasks/poweroff_d1_c1_f1.yml
blob: f3e611cdc2f9b0ab7efd83b75b582d6a95010eb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Test code for the vmware_guest_powerstate module.
# Copyright: (c) 2017, Abhijeet Kasurde <akasurde@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

- name: Wait for Flask controller to come up online
  wait_for:
    host: "{{ vcsim }}"
    port: 5000
    state: started

- name: store the vcenter container ip
  set_fact:
    vcsim: "{{ lookup('env', 'vcenter_host') }}"
- debug: var=vcsim

- name: kill vcsim
  uri:
    url: http://{{ vcsim }}:5000/killall

- name: start vcsim with folders
  uri:
    url: http://{{ vcsim }}:5000/spawn?datacenter=1&cluster=1&folder=1
  register: vcsim_instance

- name: Wait for Flask controller to come up online
  wait_for:
    host: "{{ vcsim }}"
    port: 443
    state: started

- name: get a list of VMS from vcsim
  uri:
    url: http://{{ vcsim }}:5000/govc_find?filter=VM
  register: vmlist

- debug: var=vcsim_instance
- debug: var=vmlist

# https://github.com/ansible/ansible/issues/25011
# Sending "-folders 1" to vcsim nests the datacenter under
# the folder so that the path prefix is no longer /vm
#
# /F0/DC0/vm/F0/DC0_H0_VM0

- name: set state to poweredoff on all VMs
  vmware_guest_powerstate:
    validate_certs: False
    hostname: "{{ vcsim }}"
    username: "{{ vcsim_instance['json']['username'] }}"
    password: "{{ vcsim_instance['json']['password'] }}"
    name: "{{ item|basename }}"
    state: powered-off
    folder: "{{ item|dirname }}"
  with_items: "{{ vmlist['json'] }}"
  register: poweroff_d1_c1_f1

- debug: var=poweroff_d1_c1_f1

# vcsim (v0.18.0) VMs are spawned PoweredOn
- name: make sure changes were made
  assert:
    that:
        - "poweroff_d1_c1_f1.results|map(attribute='changed')|unique|list == [True]"