summaryrefslogtreecommitdiff
path: root/test/integration/targets/vmware_host_dns/tasks/static.yml
blob: e69f50ac11c510176a43e651489ea8ebfa172017 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
- name: Tests when the hosts have a static DNS config
  block:
    # Testcase 0001: Ensure DNS config directly on the host is idempotent for static
    - name: Ensure static DNS config is idempotent when done directly on the host
      vmware_host_dns:
        hostname: '{{ esxi1 }}'
        username: '{{ esxi_user }}'
        password: '{{ esxi_password }}'
        validate_certs: False
        type: 'static'
        host_name: "{{ dns['results'][0]['hosts_dns_info'][esxi1]['host_name'] }}"
        domain: "{{ dns['results'][0]['hosts_dns_info'][esxi1]['domain_name'] }}"
        dns_servers: "{{ dns['results'][0]['hosts_dns_info'][esxi1]['ip_address'] }}"
        search_domains: "{{ dns['results'][0]['hosts_dns_info'][esxi1]['search_domain'] }}"
      register: vmware_host_dns_result_0001

    - name: Ensure DNS config wasn't changed
      assert:
        that:
          - vmware_host_dns_result_0001 is not changed

    # Testcase 0002: Ensure changing the hostname directly on the host works
    - name: Ensure changing the hostname directly on the host works
      vmware_host_dns:
        hostname: '{{ esxi1 }}'
        username: '{{ esxi_user }}'
        password: '{{ esxi_password }}'
        validate_certs: False
        type: 'static'
        host_name: newname
        domain: "{{ dns['results'][0]['hosts_dns_info'][esxi1]['domain_name'] }}"
        dns_servers: "{{ dns['results'][0]['hosts_dns_info'][esxi1]['ip_address'] }}"
        search_domains: "{{ dns['results'][0]['hosts_dns_info'][esxi1]['search_domain'] }}"
      register: vmware_host_dns_result_0002

    - name: Ensure DNS config was changed
      assert:
        that:
          - vmware_host_dns_result_0002 is changed

    # Testcase 0003: Ensure changing the domain directly on the host works
    - name: Ensure changing the domain directly on the host works
      vmware_host_dns:
        hostname: '{{ esxi1 }}'
        username: '{{ esxi_user }}'
        password: '{{ esxi_password }}'
        validate_certs: False
        type: 'static'
        host_name: newname
        domain: new.domain
        dns_servers: "{{ dns['results'][0]['hosts_dns_info'][esxi1]['ip_address'] }}"
        search_domains: "{{ dns['results'][0]['hosts_dns_info'][esxi1]['search_domain'] }}"
      register: vmware_host_dns_result_0003

    - name: Ensure DNS config was changed
      assert:
        that:
          - vmware_host_dns_result_0003 is changed

    # Testcase 0004: Ensure changing the DNS servers directly on the host works
    - name: Ensure changing the domain directly on the host works
      vmware_host_dns:
        hostname: '{{ esxi1 }}'
        username: '{{ esxi_user }}'
        password: '{{ esxi_password }}'
        validate_certs: False
        type: 'static'
        host_name: newname
        domain: new.domain
        dns_servers:
          - 1.2.3.4
          - 5.6.7.8
        search_domains: "{{ dns['results'][0]['hosts_dns_info'][esxi1]['search_domain'] }}"
      register: vmware_host_dns_result_0004

    - name: Ensure DNS config was changed
      assert:
        that:
          - vmware_host_dns_result_0004 is changed

    # Testcase 0005: Ensure changing the search domain directly on the host works
    - name: Ensure changing the domain directly on the host works
      vmware_host_dns:
        hostname: '{{ esxi1 }}'
        username: '{{ esxi_user }}'
        password: '{{ esxi_password }}'
        validate_certs: False
        type: 'static'
        host_name: newname
        domain: new.domain
        dns_servers:
          - 1.2.3.4
          - 5.6.7.8
        search_domains:
          - subdomain.example.local
          - example.local
      register: vmware_host_dns_result_0005

    - name: Ensure DNS config was changed
      assert:
        that:
          - vmware_host_dns_result_0005 is changed

    # Revert to original DNS configuration with a different search_domains
    - name: Revert to original DNS configuration
      vmware_host_dns:
        hostname: '{{ esxi1 }}'
        username: '{{ esxi_user }}'
        password: '{{ esxi_password }}'
        validate_certs: False
        type: 'static'
        host_name: "{{ dns['results'][0]['hosts_dns_info'][esxi1]['host_name'] }}"
        domain: "{{ dns['results'][0]['hosts_dns_info'][esxi1]['domain_name'] }}"
        dns_servers: "{{ dns['results'][0]['hosts_dns_info'][esxi1]['ip_address'] }}"
        search_domains: "{{ dns['results'][0]['hosts_dns_info'][esxi1]['search_domain'] }}"

    # Testcase 0006: Ensure DNS config on the cluster is idempotent for static
    - name: Apply configuration on a cluster
      vmware_host_dns:
        hostname: '{{ vcenter_hostname }}'
        username: '{{ vcenter_username }}'
        password: '{{ vcenter_password }}'
        cluster_name: "{{ ccr1 }}"
        validate_certs: False
        type: 'static'
        search_domains: "different-search-domain"
      register: vmware_host_dns_result_0006

    - name: Ensure configuration has changed
      assert:
        that:
          - vmware_host_dns_result_0006 is changed

    - name: Revert to original DNS configuration
      vmware_host_dns:
        hostname: '{{ esxi1 }}'
        username: '{{ esxi_user }}'
        password: '{{ esxi_password }}'
        validate_certs: False
        type: 'static'
        host_name: "{{ dns['results'][0]['hosts_dns_info'][esxi1]['host_name'] }}"
        domain: "{{ dns['results'][0]['hosts_dns_info'][esxi1]['domain_name'] }}"
        dns_servers: "{{ dns['results'][0]['hosts_dns_info'][esxi1]['ip_address'] }}"
        search_domains: "{{ dns['results'][0]['hosts_dns_info'][esxi1]['search_domain'] }}"

    # Testcase 0007: Ensure changing the domain on the cluster works
    - name: Ensure changing the domain on the cluster works
      vmware_host_dns:
        hostname: '{{ vcenter_hostname }}'
        username: '{{ vcenter_username }}'
        password: '{{ vcenter_password }}'
        cluster_name: "{{ ccr1 }}"
        validate_certs: False
        type: 'static'
        domain: new.domain
        dns_servers: "{{ dns['results'][0]['hosts_dns_info'][esxi1]['ip_address'] }}"
        search_domains: "{{ dns['results'][0]['hosts_dns_info'][esxi1]['search_domain'] }}"
      register: vmware_host_dns_result_0007

    - name: Ensure DNS config was changed
      assert:
        that:
          - vmware_host_dns_result_0007 is changed

    # Testcase 0008: Ensure changing the DNS servers on the cluster works
    - name: Ensure changing the DNS servers on the cluster works
      vmware_host_dns:
        hostname: '{{ vcenter_hostname }}'
        username: '{{ vcenter_username }}'
        password: '{{ vcenter_password }}'
        cluster_name: "{{ ccr1 }}"
        validate_certs: False
        type: 'static'
        domain: new.domain
        dns_servers:
          - 1.2.3.4
          - 5.6.7.8
        search_domains: "{{ dns['results'][0]['hosts_dns_info'][esxi1]['search_domain'] }}"
      register: vmware_host_dns_result_0008

    - name: Ensure DNS config was changed
      assert:
        that:
          - vmware_host_dns_result_0008 is changed

    # Testcase 0009: Ensure changing the search domains on the cluster works
    - name: Ensure changing the search domains on the cluster works
      vmware_host_dns:
        hostname: '{{ vcenter_hostname }}'
        username: '{{ vcenter_username }}'
        password: '{{ vcenter_password }}'
        cluster_name: "{{ ccr1 }}"
        validate_certs: False
        type: 'static'
        domain: new.domain
        dns_servers:
          - 1.2.3.4
          - 5.6.7.8
        search_domains:
          - subdomain.example.local
          - example.local
      register: vmware_host_dns_result_0009

    - name: Ensure DNS config was changed
      assert:
        that:
          - vmware_host_dns_result_0009 is changed

  always:
    # Revert to original DNS configuration
    - name: Revert to original DNS configuration
      vmware_host_dns:
        hostname: '{{ vcenter_hostname }}'
        username: '{{ vcenter_username }}'
        password: '{{ vcenter_password }}'
        esxi_hostname: "{{ item }}"
        validate_certs: False
        type: 'static'
        host_name: "{{ dns['results'][index]['hosts_dns_info'][item]['host_name'] }}"
        domain: "{{ dns['results'][index]['hosts_dns_info'][item]['domain_name'] }}"
        dns_servers: "{{ dns['results'][index]['hosts_dns_info'][item]['ip_address'] }}"
        search_domains: "{{ dns['results'][index]['hosts_dns_info'][item]['search_domain'] }}"
      loop: "{{ esxi_hosts }}"
      loop_control:
        index_var: index