| 1 |
--- |
| 2 |
- hosts: localhost |
| 3 |
collections: |
| 4 |
- theforeman.foreman |
| 5 |
gather_facts: false |
| 6 |
vars_files: |
| 7 |
- vars/server.yml |
| 8 |
- vars/host.yml |
| 9 |
tasks: |
| 10 |
- include_tasks: tasks/organization.yml |
| 11 |
vars: |
| 12 |
organization_name: "{{ host.organization }}" |
| 13 |
organization_state: present |
| 14 |
- include_tasks: tasks/location.yml |
| 15 |
vars: |
| 16 |
location_name: "{{ host.location }}" |
| 17 |
location_organizations: |
| 18 |
- "{{ host.organization }}" |
| 19 |
location_state: present |
| 20 |
- include_tasks: tasks/domain.yml |
| 21 |
vars: |
| 22 |
domain_name: "{{ host.domain }}" |
| 23 |
domain_locations: |
| 24 |
- "{{ host.location }}" |
| 25 |
domain_organizations: |
| 26 |
- "{{ host.organization }}" |
| 27 |
domain_state: present |
| 28 |
- include_tasks: tasks/subnet.yml |
| 29 |
vars: |
| 30 |
subnet_name: "{{ host.subnet }}" |
| 31 |
subnet_network: '192.0.2.0' |
| 32 |
subnet_mask: '255.255.255.0' |
| 33 |
subnet_domains: |
| 34 |
- "{{ host.domain }}" |
| 35 |
subnet_locations: |
| 36 |
- "{{ host.location }}" |
| 37 |
subnet_organizations: |
| 38 |
- "{{ host.organization }}" |
| 39 |
subnet_state: present |
| 40 |
- include_tasks: tasks/subnet.yml |
| 41 |
vars: |
| 42 |
subnet_name: "{{ host.subnet }} Secondary" |
| 43 |
subnet_network: '198.51.100.0' |
| 44 |
subnet_mask: '255.255.255.0' |
| 45 |
subnet_domains: |
| 46 |
- "{{ host.domain }}" |
| 47 |
subnet_locations: |
| 48 |
- "{{ host.location }}" |
| 49 |
subnet_organizations: |
| 50 |
- "{{ host.organization }}" |
| 51 |
subnet_state: present |
| 52 |
- include_tasks: tasks/hostgroup.yml |
| 53 |
vars: |
| 54 |
hostgroup_name: "{{ host.hostgroup }}" |
| 55 |
hostgroup_domain: "{{ host.domain }}" |
| 56 |
hostgroup_locations: |
| 57 |
- "{{ host.location }}" |
| 58 |
hostgroup_organizations: |
| 59 |
- "{{ host.organization }}" |
| 60 |
hostgroup_state: present |
| 61 |
- include_tasks: tasks/architecture.yml |
| 62 |
vars: |
| 63 |
architecture_name: "{{ host.arch }}" |
| 64 |
architecture_state: present |
| 65 |
- include_tasks: tasks/operatingsystem.yml |
| 66 |
vars: |
| 67 |
operatingsystem_name: "{{ host.os.name }}" |
| 68 |
operatingsystem_major: "{{ host.os.major }}" |
| 69 |
operatingsystem_minor: "{{ host.os.minor }}" |
| 70 |
operatingsystem_family: "{{ host.os.family }}" |
| 71 |
operatingsystem_architectures: |
| 72 |
- "{{ host.arch }}" |
| 73 |
operatingsystem_state: present |
| 74 |
- include_tasks: tasks/host.yml |
| 75 |
vars: |
| 76 |
host_name: "test-host.{{ host.domain }}" |
| 77 |
host_state: absent |
| 78 |
|
| 79 |
- hosts: tests |
| 80 |
collections: |
| 81 |
- theforeman.foreman |
| 82 |
gather_facts: false |
| 83 |
vars_files: |
| 84 |
- vars/server.yml |
| 85 |
- vars/host.yml |
| 86 |
tasks: |
| 87 |
- name: create host |
| 88 |
include_tasks: tasks/host.yml |
| 89 |
vars: |
| 90 |
host_name: "test-host.{{ host.domain }}" |
| 91 |
host_organization: "{{ host.organization }}" |
| 92 |
host_location: "{{ host.location }}" |
| 93 |
host_managed: false |
| 94 |
host_interfaces_attributes: |
| 95 |
- type: "interface" |
| 96 |
identifier: "fam01" |
| 97 |
ip: "192.0.2.23" |
| 98 |
mac: "EE:FF:00:00:00:01" |
| 99 |
subnet: "{{ host.subnet }}" |
| 100 |
expected_change: true |
| 101 |
|
| 102 |
- name: create host again, no change |
| 103 |
include_tasks: tasks/host.yml |
| 104 |
vars: |
| 105 |
host_name: "test-host.{{ host.domain }}" |
| 106 |
host_organization: "{{ host.organization }}" |
| 107 |
host_location: "{{ host.location }}" |
| 108 |
host_managed: false |
| 109 |
host_interfaces_attributes: |
| 110 |
- type: "interface" |
| 111 |
identifier: "fam01" |
| 112 |
ip: "192.0.2.23" |
| 113 |
mac: "EE:FF:00:00:00:01" |
| 114 |
subnet: "{{ host.subnet }}" |
| 115 |
expected_change: false |
| 116 |
|
| 117 |
- name: update host, add new interface |
| 118 |
include_tasks: tasks/host.yml |
| 119 |
vars: |
| 120 |
host_name: "test-host.{{ host.domain }}" |
| 121 |
host_organization: "{{ host.organization }}" |
| 122 |
host_location: "{{ host.location }}" |
| 123 |
host_managed: false |
| 124 |
host_interfaces_attributes: |
| 125 |
- type: "interface" |
| 126 |
identifier: "fam01" |
| 127 |
ip: "192.0.2.23" |
| 128 |
mac: "EE:FF:00:00:00:01" |
| 129 |
subnet: "{{ host.subnet }}" |
| 130 |
- type: "interface" |
| 131 |
identifier: "fam02" |
| 132 |
ip: "198.51.100.42" |
| 133 |
mac: "EE:FF:00:00:00:02" |
| 134 |
subnet: "{{ host.subnet }} Secondary" |
| 135 |
expected_change: true |
| 136 |
|
| 137 |
- name: update host, add new interface again, no change |
| 138 |
include_tasks: tasks/host.yml |
| 139 |
vars: |
| 140 |
host_name: "test-host.{{ host.domain }}" |
| 141 |
host_organization: "{{ host.organization }}" |
| 142 |
host_location: "{{ host.location }}" |
| 143 |
host_managed: false |
| 144 |
host_interfaces_attributes: |
| 145 |
- type: "interface" |
| 146 |
identifier: "fam01" |
| 147 |
ip: "192.0.2.23" |
| 148 |
mac: "EE:FF:00:00:00:01" |
| 149 |
subnet: "{{ host.subnet }}" |
| 150 |
- type: "interface" |
| 151 |
identifier: "fam02" |
| 152 |
ip: "198.51.100.42" |
| 153 |
mac: "EE:FF:00:00:00:02" |
| 154 |
subnet: "{{ host.subnet }} Secondary" |
| 155 |
expected_change: false |
| 156 |
|
| 157 |
- name: update host, delete interface |
| 158 |
include_tasks: tasks/host.yml |
| 159 |
vars: |
| 160 |
host_name: "test-host.{{ host.domain }}" |
| 161 |
host_organization: "{{ host.organization }}" |
| 162 |
host_location: "{{ host.location }}" |
| 163 |
host_managed: false |
| 164 |
host_interfaces_attributes: |
| 165 |
- type: "interface" |
| 166 |
identifier: "fam02" |
| 167 |
ip: "198.51.100.42" |
| 168 |
mac: "EE:FF:00:00:00:02" |
| 169 |
subnet: "{{ host.subnet }} Secondary" |
| 170 |
expected_change: true |
| 171 |
|
| 172 |
- name: update host, delete interface again, no change |
| 173 |
include_tasks: tasks/host.yml |
| 174 |
vars: |
| 175 |
host_name: "test-host.{{ host.domain }}" |
| 176 |
host_organization: "{{ host.organization }}" |
| 177 |
host_location: "{{ host.location }}" |
| 178 |
host_managed: false |
| 179 |
host_interfaces_attributes: |
| 180 |
- type: "interface" |
| 181 |
identifier: "fam02" |
| 182 |
ip: "198.51.100.42" |
| 183 |
mac: "EE:FF:00:00:00:02" |
| 184 |
subnet: "{{ host.subnet }} Secondary" |
| 185 |
expected_change: false |
| 186 |
|
| 187 |
- name: update host, make interfaces bond |
| 188 |
include_tasks: tasks/host.yml |
| 189 |
vars: |
| 190 |
host_name: "test-host.{{ host.domain }}" |
| 191 |
host_organization: "{{ host.organization }}" |
| 192 |
host_location: "{{ host.location }}" |
| 193 |
host_managed: false |
| 194 |
host_interfaces_attributes: |
| 195 |
- identifier: eth0 |
| 196 |
mac: aa:bb:cc:dd:ee:ff |
| 197 |
type: interface |
| 198 |
managed: true |
| 199 |
primary: false |
| 200 |
provision: false |
| 201 |
- identifier: eth1 |
| 202 |
mac: aa:bb:cc:dd:ee:ee |
| 203 |
type: interface |
| 204 |
managed: true |
| 205 |
primary: false |
| 206 |
provision: false |
| 207 |
- identifier: bond0 |
| 208 |
mac: aa:bb:cc:dd:ee:ff |
| 209 |
type: bond |
| 210 |
managed: true |
| 211 |
primary: true |
| 212 |
provision: true |
| 213 |
mode: 802.3ad |
| 214 |
attached_devices: |
| 215 |
- eth0 |
| 216 |
- eth1 |
| 217 |
bond_options: "miimon=100 lacp_rate=1" |
| 218 |
ip: "192.0.2.100" |
| 219 |
expected_change: true |
| 220 |
|
| 221 |
- name: update host, make interfaces bond again, no change |
| 222 |
include_tasks: tasks/host.yml |
| 223 |
vars: |
| 224 |
host_name: "test-host.{{ host.domain }}" |
| 225 |
host_organization: "{{ host.organization }}" |
| 226 |
host_location: "{{ host.location }}" |
| 227 |
host_managed: false |
| 228 |
host_interfaces_attributes: |
| 229 |
- identifier: eth0 |
| 230 |
mac: aa:bb:cc:dd:ee:ff |
| 231 |
type: interface |
| 232 |
managed: true |
| 233 |
primary: false |
| 234 |
provision: false |
| 235 |
- identifier: eth1 |
| 236 |
mac: aa:bb:cc:dd:ee:ee |
| 237 |
type: interface |
| 238 |
managed: true |
| 239 |
primary: false |
| 240 |
provision: false |
| 241 |
- identifier: bond0 |
| 242 |
mac: aa:bb:cc:dd:ee:ff |
| 243 |
type: bond |
| 244 |
managed: true |
| 245 |
primary: true |
| 246 |
provision: true |
| 247 |
mode: 802.3ad |
| 248 |
attached_devices: |
| 249 |
- eth0 |
| 250 |
- eth1 |
| 251 |
bond_options: "miimon=100 lacp_rate=1" |
| 252 |
ip: "192.0.2.100" |
| 253 |
expected_change: false |
| 254 |
|
| 255 |
- name: delete host |
| 256 |
include_tasks: tasks/host.yml |
| 257 |
vars: |
| 258 |
host_name: "test-host.{{ host.domain }}" |
| 259 |
host_state: absent |
| 260 |
expected_change: true |
| 261 |
|
| 262 |
- name: delete host again, no change |
| 263 |
include_tasks: tasks/host.yml |
| 264 |
vars: |
| 265 |
host_name: "test-host.{{ host.domain }}" |
| 266 |
host_state: absent |
| 267 |
expected_change: false |
| 268 |
|
| 269 |
- hosts: localhost |
| 270 |
collections: |
| 271 |
- theforeman.foreman |
| 272 |
gather_facts: false |
| 273 |
vars_files: |
| 274 |
- vars/server.yml |
| 275 |
- vars/host.yml |
| 276 |
tasks: |
| 277 |
- include_tasks: tasks/hostgroup.yml |
| 278 |
vars: |
| 279 |
hostgroup_name: "{{ host.hostgroup }}" |
| 280 |
hostgroup_state: absent |
| 281 |
- include_tasks: tasks/subnet.yml |
| 282 |
vars: |
| 283 |
subnet_name: "{{ host.subnet }}" |
| 284 |
subnet_mask: '255.255.255.224' |
| 285 |
subnet_domains: [] |
| 286 |
subnet_state: present |
| 287 |
- include_tasks: tasks/subnet.yml |
| 288 |
vars: |
| 289 |
subnet_name: "{{ host.subnet }} Secondary" |
| 290 |
subnet_mask: '255.255.255.224' |
| 291 |
subnet_domains: [] |
| 292 |
subnet_state: present |
| 293 |
- include_tasks: tasks/subnet.yml |
| 294 |
vars: |
| 295 |
subnet_name: "{{ host.subnet }}" |
| 296 |
subnet_mask: '255.255.255.224' |
| 297 |
subnet_state: absent |
| 298 |
- include_tasks: tasks/subnet.yml |
| 299 |
vars: |
| 300 |
subnet_name: "{{ host.subnet }} Secondary" |
| 301 |
subnet_mask: '255.255.255.224' |
| 302 |
subnet_state: absent |
| 303 |
- include_tasks: tasks/domain.yml |
| 304 |
vars: |
| 305 |
domain_name: "{{ host.domain }}" |
| 306 |
domain_state: absent |
| 307 |
- include_tasks: tasks/operatingsystem.yml |
| 308 |
vars: |
| 309 |
operatingsystem_name: "{{ host.os.name }}" |
| 310 |
operatingsystem_state: absent |
| 311 |
- include_tasks: tasks/architecture.yml |
| 312 |
vars: |
| 313 |
architecture_name: "{{ host.arch }}" |
| 314 |
architecture_state: absent |
| 315 |
- include_tasks: tasks/location.yml |
| 316 |
vars: |
| 317 |
location_name: "{{ host.location }}" |
| 318 |
location_state: absent |
| 319 |
- include_tasks: tasks/organization.yml |
| 320 |
vars: |
| 321 |
organization_name: "{{ host.organization }}" |
| 322 |
organization_state: absent |
| 323 |
... |