| 1 |
# Test code for the vmware_host_ntp module. |
| 2 |
# Copyright: (c) 2018, Abhijeet Kasurde <[email protected]> |
| 3 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 4 |
|
| 5 |
- import_role: |
| 6 |
name: prepare_vmware_tests |
| 7 |
vars: |
| 8 |
setup_attach_host: true |
| 9 |
|
| 10 |
- name: Add NTP server to a host |
| 11 |
community.vmware.vmware_host_ntp: |
| 12 |
hostname: "{{ vcenter_hostname }}" |
| 13 |
username: "{{ vcenter_username }}" |
| 14 |
password: "{{ vcenter_password }}" |
| 15 |
esxi_hostname: '{{ esxi1 }}' |
| 16 |
state: present |
| 17 |
ntp_servers: |
| 18 |
- 192.0.2.1 |
| 19 |
validate_certs: false |
| 20 |
register: present |
| 21 |
|
| 22 |
- name: Make sure that NTP setting has been changed |
| 23 |
assert: |
| 24 |
that: |
| 25 |
- present.changed is sameas true |
| 26 |
|
| 27 |
- name: Add another NTP server to a host |
| 28 |
community.vmware.vmware_host_ntp: |
| 29 |
hostname: "{{ vcenter_hostname }}" |
| 30 |
username: "{{ vcenter_username }}" |
| 31 |
password: "{{ vcenter_password }}" |
| 32 |
esxi_hostname: '{{ esxi1 }}' |
| 33 |
state: present |
| 34 |
ntp_servers: |
| 35 |
- 198.51.100.1 |
| 36 |
validate_certs: false |
| 37 |
register: present |
| 38 |
|
| 39 |
- name: Make sure that NTP setting has been changed |
| 40 |
assert: |
| 41 |
that: |
| 42 |
- present.changed is sameas true |
| 43 |
|
| 44 |
- name: Remove NTP server from a host |
| 45 |
community.vmware.vmware_host_ntp: |
| 46 |
hostname: "{{ vcenter_hostname }}" |
| 47 |
username: "{{ vcenter_username }}" |
| 48 |
password: "{{ vcenter_password }}" |
| 49 |
esxi_hostname: '{{ esxi1 }}' |
| 50 |
state: absent |
| 51 |
ntp_servers: |
| 52 |
- 198.51.100.1 |
| 53 |
validate_certs: false |
| 54 |
register: absent_one |
| 55 |
|
| 56 |
- name: Make sure that NTP setting has been changed |
| 57 |
assert: |
| 58 |
that: |
| 59 |
- absent_one.changed is sameas true |
| 60 |
|
| 61 |
- name: Add more NTP servers to a host |
| 62 |
community.vmware.vmware_host_ntp: |
| 63 |
hostname: "{{ vcenter_hostname }}" |
| 64 |
username: "{{ vcenter_username }}" |
| 65 |
password: "{{ vcenter_password }}" |
| 66 |
esxi_hostname: '{{ esxi1 }}' |
| 67 |
state: present |
| 68 |
ntp_servers: |
| 69 |
- 203.0.113.1 |
| 70 |
- 192.0.2.2 |
| 71 |
- 198.51.100.2 |
| 72 |
validate_certs: false |
| 73 |
register: present |
| 74 |
|
| 75 |
- name: Make sure that NTP setting has been changed |
| 76 |
assert: |
| 77 |
that: |
| 78 |
- present.changed is sameas true |
| 79 |
|
| 80 |
- name: Remove all NTP servers from a host |
| 81 |
community.vmware.vmware_host_ntp: |
| 82 |
hostname: "{{ vcenter_hostname }}" |
| 83 |
username: "{{ vcenter_username }}" |
| 84 |
password: "{{ vcenter_password }}" |
| 85 |
esxi_hostname: '{{ esxi1 }}' |
| 86 |
state: absent |
| 87 |
ntp_servers: |
| 88 |
- 192.0.2.1 |
| 89 |
- 203.0.113.1 |
| 90 |
- 192.0.2.2 |
| 91 |
- 198.51.100.2 |
| 92 |
validate_certs: false |
| 93 |
register: absent_all |
| 94 |
|
| 95 |
- name: Make sure that NTP setting has been changed |
| 96 |
assert: |
| 97 |
that: |
| 98 |
- absent_all.changed is sameas true |
| 99 |
|
| 100 |
- name: Configure NTP servers for a host |
| 101 |
community.vmware.vmware_host_ntp: |
| 102 |
hostname: "{{ vcenter_hostname }}" |
| 103 |
username: "{{ vcenter_username }}" |
| 104 |
password: "{{ vcenter_password }}" |
| 105 |
esxi_hostname: '{{ esxi1 }}' |
| 106 |
ntp_servers: |
| 107 |
- 192.0.2.1 |
| 108 |
- 198.51.100.1 |
| 109 |
- 203.0.113.1 |
| 110 |
validate_certs: false |
| 111 |
register: ntp_servers |
| 112 |
|
| 113 |
- name: Make sure that NTP setting has been changed |
| 114 |
assert: |
| 115 |
that: |
| 116 |
- ntp_servers.changed is sameas true |
| 117 |
|
| 118 |
- name: Configure NTP servers for a host |
| 119 |
community.vmware.vmware_host_ntp: |
| 120 |
hostname: "{{ vcenter_hostname }}" |
| 121 |
username: "{{ vcenter_username }}" |
| 122 |
password: "{{ vcenter_password }}" |
| 123 |
esxi_hostname: '{{ esxi1 }}' |
| 124 |
ntp_servers: |
| 125 |
- 192.0.2.2 |
| 126 |
- 198.51.100.2 |
| 127 |
- 203.0.113.2 |
| 128 |
verbose: true |
| 129 |
validate_certs: false |
| 130 |
register: ntp_servers |
| 131 |
|
| 132 |
- name: Make sure that NTP setting has been changed |
| 133 |
assert: |
| 134 |
that: |
| 135 |
- ntp_servers.changed is sameas true |
| 136 |
|
| 137 |
- name: Add NTP server to a host in check mode |
| 138 |
community.vmware.vmware_host_ntp: |
| 139 |
hostname: "{{ vcenter_hostname }}" |
| 140 |
username: "{{ vcenter_username }}" |
| 141 |
password: "{{ vcenter_password }}" |
| 142 |
esxi_hostname: '{{ esxi1 }}' |
| 143 |
state: present |
| 144 |
ntp_servers: |
| 145 |
- 192.0.2.1 |
| 146 |
validate_certs: false |
| 147 |
register: present |
| 148 |
check_mode: true |
| 149 |
|
| 150 |
- name: Make sure that NTP setting has been changed |
| 151 |
assert: |
| 152 |
that: |
| 153 |
- present.changed is sameas true |
| 154 |
|
| 155 |
- name: Remove NTP server to a host in check mode |
| 156 |
community.vmware.vmware_host_ntp: |
| 157 |
hostname: "{{ vcenter_hostname }}" |
| 158 |
username: "{{ vcenter_username }}" |
| 159 |
password: "{{ vcenter_password }}" |
| 160 |
esxi_hostname: '{{ esxi1 }}' |
| 161 |
state: absent |
| 162 |
ntp_servers: |
| 163 |
- 192.0.2.1 |
| 164 |
validate_certs: false |
| 165 |
register: present |
| 166 |
check_mode: true |
| 167 |
|
| 168 |
- name: Make sure that NTP setting hasn't been changed |
| 169 |
assert: |
| 170 |
that: |
| 171 |
- present.changed is sameas false |
| 172 |
|
| 173 |
- name: Configure NTP servers for a host in check mode |
| 174 |
community.vmware.vmware_host_ntp: |
| 175 |
hostname: "{{ vcenter_hostname }}" |
| 176 |
username: "{{ vcenter_username }}" |
| 177 |
password: "{{ vcenter_password }}" |
| 178 |
esxi_hostname: '{{ esxi1 }}' |
| 179 |
ntp_servers: |
| 180 |
- 192.0.2.1 |
| 181 |
- 198.51.100.1 |
| 182 |
- 203.0.113.1 |
| 183 |
validate_certs: false |
| 184 |
register: ntp_servers |
| 185 |
check_mode: true |
| 186 |
|
| 187 |
- name: Make sure that NTP setting will be changed |
| 188 |
assert: |
| 189 |
that: |
| 190 |
- ntp_servers.changed is sameas true |
| 191 |
|
| 192 |
# https://github.com/ansible-collections/community.vmware/pull/588 |
| 193 |
- name: The integration tests when ESXi disconnected |
| 194 |
block: |
| 195 |
- name: Disconnect ESXi |
| 196 |
vmware.vmware.esxi_connection: |
| 197 |
hostname: "{{ vcenter_hostname }}" |
| 198 |
username: "{{ vcenter_username }}" |
| 199 |
password: "{{ vcenter_password }}" |
| 200 |
validate_certs: false |
| 201 |
datacenter: "{{ dc1 }}" |
| 202 |
esxi_host_name: '{{ esxi1 }}' |
| 203 |
state: disconnected |
| 204 |
register: disconnect_esxi_result |
| 205 |
|
| 206 |
- name: Make sure if ESXi host disconnected |
| 207 |
assert: |
| 208 |
that: |
| 209 |
- disconnect_esxi_result.changed is sameas true |
| 210 |
|
| 211 |
- name: Add NTP server to disconnected ESXi with check_mode |
| 212 |
community.vmware.vmware_host_ntp: |
| 213 |
hostname: "{{ vcenter_hostname }}" |
| 214 |
username: "{{ vcenter_username }}" |
| 215 |
password: "{{ vcenter_password }}" |
| 216 |
validate_certs: false |
| 217 |
esxi_hostname: '{{ esxi1 }}' |
| 218 |
state: present |
| 219 |
ntp_servers: |
| 220 |
- 192.0.2.1 |
| 221 |
check_mode: true |
| 222 |
register: add_ntp_server_disconnected_esxi_check_mode_result |
| 223 |
|
| 224 |
- name: Make sure if the changed doesn't occur |
| 225 |
assert: |
| 226 |
that: |
| 227 |
- add_ntp_server_disconnected_esxi_check_mode_result.changed is sameas false |
| 228 |
|
| 229 |
- name: Add NTP server to disconnected ESXi |
| 230 |
community.vmware.vmware_host_ntp: |
| 231 |
hostname: "{{ vcenter_hostname }}" |
| 232 |
username: "{{ vcenter_username }}" |
| 233 |
password: "{{ vcenter_password }}" |
| 234 |
validate_certs: false |
| 235 |
esxi_hostname: '{{ esxi1 }}' |
| 236 |
state: present |
| 237 |
ntp_servers: |
| 238 |
- 192.0.2.1 |
| 239 |
register: add_ntp_server_disconnected_esxi_result |
| 240 |
|
| 241 |
- name: Make sure if the changed doesn't occur |
| 242 |
assert: |
| 243 |
that: |
| 244 |
- add_ntp_server_disconnected_esxi_result.changed is sameas false |
| 245 |
|
| 246 |
- name: Reconnect ESXi |
| 247 |
vmware.vmware.esxi_connection: |
| 248 |
hostname: "{{ vcenter_hostname }}" |
| 249 |
username: "{{ vcenter_username }}" |
| 250 |
password: "{{ vcenter_password }}" |
| 251 |
validate_certs: false |
| 252 |
datacenter: "{{ dc1 }}" |
| 253 |
esxi_host_name: '{{ esxi1 }}' |
| 254 |
state: connected |
| 255 |
register: reconnect_esxi_result |
| 256 |
|
| 257 |
- name: Make sure if ESXi host reconnected |
| 258 |
assert: |
| 259 |
that: |
| 260 |
- reconnect_esxi_result.changed is sameas true |