| 1 |
--- |
| 2 |
- hosts: facthost7 |
| 3 |
tags: [ 'fact_negation' ] |
| 4 |
connection: local |
| 5 |
gather_subset: "!hardware" |
| 6 |
gather_facts: no |
| 7 |
tasks: |
| 8 |
- name: setup with not hardware |
| 9 |
setup: |
| 10 |
gather_subset: |
| 11 |
- "!hardware" |
| 12 |
register: not_hardware_facts |
| 13 |
|
| 14 |
- name: min and network test for platform added |
| 15 |
hosts: facthost21 |
| 16 |
tags: [ 'fact_network' ] |
| 17 |
connection: local |
| 18 |
gather_subset: ["!all", "network"] |
| 19 |
gather_facts: yes |
| 20 |
tasks: |
| 21 |
- name: Test that retrieving network facts works and gets prereqs from platform and distribution |
| 22 |
assert: |
| 23 |
that: |
| 24 |
- 'ansible_default_ipv4|default("UNDEF") != "UNDEF"' |
| 25 |
- 'ansible_interfaces|default("UNDEF") != "UNDEF"' |
| 26 |
# these are true for linux, but maybe not for other os |
| 27 |
- 'ansible_system|default("UNDEF") != "UNDEF"' |
| 28 |
- 'ansible_distribution|default("UNDEF") != "UNDEF"' |
| 29 |
# always emitted by the distribution collector (null when the distro has no CPE_NAME) |
| 30 |
- 'ansible_distribution_cpe_name is defined' |
| 31 |
# we dont really require these but they are in the min set |
| 32 |
# - 'ansible_virtualization_role|default("UNDEF") == "UNDEF"' |
| 33 |
# - 'ansible_user_id|default("UNDEF") == "UNDEF"' |
| 34 |
# - 'ansible_env|default("UNDEF") == "UNDEF"' |
| 35 |
# - 'ansible_selinux|default("UNDEF") == "UNDEF"' |
| 36 |
# - 'ansible_pkg_mgr|default("UNDEF") == "UNDEF"' |
| 37 |
|
| 38 |
- name: min and hardware test for platform added |
| 39 |
hosts: facthost22 |
| 40 |
tags: [ 'fact_hardware' ] |
| 41 |
connection: local |
| 42 |
gather_subset: "hardware" |
| 43 |
gather_facts: yes |
| 44 |
tasks: |
| 45 |
- name: debug stuff |
| 46 |
debug: |
| 47 |
var: hostvars['facthost22'] |
| 48 |
# we should also collect platform, but not distribution |
| 49 |
- name: Test that retrieving hardware facts works and gets prereqs from platform and distribution |
| 50 |
when: ansible_system|default("UNDEF") == "Linux" |
| 51 |
assert: |
| 52 |
# LinuxHardwareCollector requires 'platform' facts |
| 53 |
that: |
| 54 |
- 'ansible_memory_mb|default("UNDEF") != "UNDEF"' |
| 55 |
- 'ansible_default_ipv4|default("UNDEF") == "UNDEF"' |
| 56 |
- 'ansible_interfaces|default("UNDEF") == "UNDEF"' |
| 57 |
# these are true for linux, but maybe not for other os |
| 58 |
# hardware requires 'platform' |
| 59 |
- 'ansible_system|default("UNDEF") != "UNDEF"' |
| 60 |
- 'ansible_machine|default("UNDEF") != "UNDEF"' |
| 61 |
# hardware does not require 'distribution' but it is min set |
| 62 |
# - 'ansible_distribution|default("UNDEF") == "UNDEF"' |
| 63 |
# we dont really require these but they are in the min set |
| 64 |
# - 'ansible_virtualization_role|default("UNDEF") == "UNDEF"' |
| 65 |
# - 'ansible_user_id|default("UNDEF") == "UNDEF"' |
| 66 |
# - 'ansible_env|default("UNDEF") == "UNDEF"' |
| 67 |
# - 'ansible_selinux|default("UNDEF") == "UNDEF"' |
| 68 |
# - 'ansible_pkg_mgr|default("UNDEF") == "UNDEF"' |
| 69 |
|
| 70 |
- name: min and service_mgr test for platform added |
| 71 |
hosts: facthost23 |
| 72 |
tags: [ 'fact_service_mgr' ] |
| 73 |
connection: local |
| 74 |
gather_subset: ["!all", "service_mgr"] |
| 75 |
gather_facts: yes |
| 76 |
tasks: |
| 77 |
- name: Test that retrieving service_mgr facts works and gets prereqs from platform and distribution |
| 78 |
assert: |
| 79 |
that: |
| 80 |
- 'ansible_service_mgr|default("UNDEF") != "UNDEF"' |
| 81 |
- 'ansible_default_ipv4|default("UNDEF") == "UNDEF"' |
| 82 |
- 'ansible_interfaces|default("UNDEF") == "UNDEF"' |
| 83 |
# these are true for linux, but maybe not for other os |
| 84 |
- 'ansible_system|default("UNDEF") != "UNDEF"' |
| 85 |
- 'ansible_distribution|default("UNDEF") != "UNDEF"' |
| 86 |
# we dont really require these but they are in the min set |
| 87 |
# - 'ansible_virtualization_role|default("UNDEF") == "UNDEF"' |
| 88 |
# - 'ansible_user_id|default("UNDEF") == "UNDEF"' |
| 89 |
# - 'ansible_env|default("UNDEF") == "UNDEF"' |
| 90 |
# - 'ansible_selinux|default("UNDEF") == "UNDEF"' |
| 91 |
# - 'ansible_pkg_mgr|default("UNDEF") == "UNDEF"' |
| 92 |
|
| 93 |
- hosts: facthost0 |
| 94 |
tags: [ 'fact_min' ] |
| 95 |
connection: local |
| 96 |
gather_subset: "all" |
| 97 |
gather_facts: yes |
| 98 |
tasks: |
| 99 |
#- setup: |
| 100 |
# register: facts |
| 101 |
- name: Test that retrieving all facts works |
| 102 |
assert: |
| 103 |
that: |
| 104 |
- 'ansible_user_id|default("UNDEF_MIN") != "UNDEF_MIN"' |
| 105 |
- 'ansible_interfaces|default("UNDEF_NET") != "UNDEF_NET"' |
| 106 |
- 'ansible_mounts|default("UNDEF_MOUNT") != "UNDEF_MOUNT" or ansible_distribution == "MacOSX"' |
| 107 |
- 'ansible_virtualization_role|default("UNDEF_VIRT") != "UNDEF_VIRT"' |
| 108 |
|
| 109 |
- hosts: facthost1 |
| 110 |
tags: [ 'fact_min' ] |
| 111 |
connection: local |
| 112 |
gather_facts: no |
| 113 |
tasks: |
| 114 |
- name: Test that we can retrieve the loadavg fact |
| 115 |
setup: |
| 116 |
filter: "ansible_loadavg" |
| 117 |
|
| 118 |
- name: Test the contents of the loadavg fact |
| 119 |
assert: |
| 120 |
that: |
| 121 |
- 'ansible_loadavg|default("UNDEF_ENV") != "UNDEF_ENV"' |
| 122 |
- '"1m" in ansible_loadavg and ansible_loadavg["1m"] is float' |
| 123 |
- '"5m" in ansible_loadavg and ansible_loadavg["5m"] is float' |
| 124 |
- '"15m" in ansible_loadavg and ansible_loadavg["15m"] is float' |
| 125 |
|
| 126 |
- hosts: facthost19 |
| 127 |
tags: [ 'fact_min' ] |
| 128 |
connection: local |
| 129 |
gather_facts: no |
| 130 |
tasks: |
| 131 |
- setup: |
| 132 |
filter: "*env*" |
| 133 |
# register: fact_results |
| 134 |
|
| 135 |
- name: Test that retrieving all facts filtered to env works |
| 136 |
assert: |
| 137 |
that: |
| 138 |
- 'ansible_interfaces|default("UNDEF_NET") == "UNDEF_NET"' |
| 139 |
- 'ansible_mounts|default("UNDEF_MOUNT") == "UNDEF_MOUNT"' |
| 140 |
- 'ansible_virtualization_role|default("UNDEF_VIRT") == "UNDEF_VIRT"' |
| 141 |
- 'ansible_env|default("UNDEF_ENV") != "UNDEF_ENV"' |
| 142 |
|
| 143 |
- hosts: facthost24 |
| 144 |
tags: [ 'fact_min' ] |
| 145 |
connection: local |
| 146 |
gather_facts: no |
| 147 |
tasks: |
| 148 |
- setup: |
| 149 |
filter: |
| 150 |
- "*env*" |
| 151 |
- "*virt*" |
| 152 |
|
| 153 |
- name: Test that retrieving all facts filtered to env and virt works |
| 154 |
assert: |
| 155 |
that: |
| 156 |
- 'ansible_interfaces|default("UNDEF_NET") == "UNDEF_NET"' |
| 157 |
- 'ansible_mounts|default("UNDEF_MOUNT") == "UNDEF_MOUNT"' |
| 158 |
- 'ansible_virtualization_role|default("UNDEF_VIRT") != "UNDEF_VIRT"' |
| 159 |
- 'ansible_env|default("UNDEF_ENV") != "UNDEF_ENV"' |
| 160 |
|
| 161 |
- hosts: facthost25 |
| 162 |
tags: [ 'fact_min' ] |
| 163 |
gather_facts: no |
| 164 |
tasks: |
| 165 |
- setup: |
| 166 |
filter: |
| 167 |
- "date_time" |
| 168 |
|
| 169 |
- name: Test that retrieving all facts filtered to date_time even w/o using ansible_ prefix |
| 170 |
assert: |
| 171 |
that: |
| 172 |
- 'ansible_facts["date_time"]|default("UNDEF_MOUNT") != "UNDEF_MOUNT"' |
| 173 |
- 'ansible_date_time|default("UNDEF_MOUNT") != "UNDEF_MOUNT"' |
| 174 |
|
| 175 |
- hosts: facthost26 |
| 176 |
tags: [ 'fact_min' ] |
| 177 |
gather_facts: no |
| 178 |
tasks: |
| 179 |
- setup: |
| 180 |
filter: |
| 181 |
- "ansible_date_time" |
| 182 |
|
| 183 |
- name: Test that retrieving all facts filtered to date_time even using ansible_ prefix |
| 184 |
assert: |
| 185 |
that: |
| 186 |
- 'ansible_facts["date_time"]|default("UNDEF_MOUNT") != "UNDEF_MOUNT"' |
| 187 |
- 'ansible_date_time|default("UNDEF_MOUNT") != "UNDEF_MOUNT"' |
| 188 |
|
| 189 |
- hosts: facthost13 |
| 190 |
tags: [ 'fact_min' ] |
| 191 |
connection: local |
| 192 |
gather_facts: no |
| 193 |
tasks: |
| 194 |
- setup: |
| 195 |
filter: "ansible_user_id" |
| 196 |
# register: fact_results |
| 197 |
|
| 198 |
- name: Test that retrieving all facts filtered to specific fact ansible_user_id works |
| 199 |
assert: |
| 200 |
that: |
| 201 |
- 'ansible_user_id|default("UNDEF_USER") != "UNDEF_USER"' |
| 202 |
- 'ansible_interfaces|default("UNDEF_NET") == "UNDEF_NET"' |
| 203 |
- 'ansible_mounts|default("UNDEF_MOUNT") == "UNDEF_MOUNT"' |
| 204 |
- 'ansible_virtualization_role|default("UNDEF_VIRT") == "UNDEF_VIRT"' |
| 205 |
- 'ansible_env|default("UNDEF_ENV") == "UNDEF_ENV"' |
| 206 |
- 'ansible_pkg_mgr|default("UNDEF_PKG_MGR") == "UNDEF_PKG_MGR"' |
| 207 |
|
| 208 |
- hosts: facthost11 |
| 209 |
tags: [ 'fact_min' ] |
| 210 |
connection: local |
| 211 |
gather_facts: no |
| 212 |
tasks: |
| 213 |
- setup: |
| 214 |
filter: "*" |
| 215 |
# register: fact_results |
| 216 |
|
| 217 |
- name: Test that retrieving all facts filtered to splat |
| 218 |
assert: |
| 219 |
that: |
| 220 |
- 'ansible_user_id|default("UNDEF_MIN") != "UNDEF_MIN"' |
| 221 |
- 'ansible_interfaces|default("UNDEF_NET") != "UNDEF_NET"' |
| 222 |
- 'ansible_mounts|default("UNDEF_MOUNT") != "UNDEF_MOUNT" or ansible_distribution == "MacOSX"' |
| 223 |
- 'ansible_virtualization_role|default("UNDEF_VIRT") != "UNDEF_VIRT"' |
| 224 |
|
| 225 |
- hosts: facthost12 |
| 226 |
tags: [ 'fact_min' ] |
| 227 |
connection: local |
| 228 |
gather_facts: no |
| 229 |
tasks: |
| 230 |
- setup: |
| 231 |
filter: "" |
| 232 |
# register: fact_results |
| 233 |
|
| 234 |
- name: Test that retrieving all facts filtered to empty filter_spec works |
| 235 |
assert: |
| 236 |
that: |
| 237 |
- 'ansible_user_id|default("UNDEF_MIN") != "UNDEF_MIN"' |
| 238 |
- 'ansible_interfaces|default("UNDEF_NET") != "UNDEF_NET"' |
| 239 |
- 'ansible_mounts|default("UNDEF_MOUNT") != "UNDEF_MOUNT" or ansible_distribution == "MacOSX"' |
| 240 |
- 'ansible_virtualization_role|default("UNDEF_VIRT") != "UNDEF_VIRT"' |
| 241 |
|
| 242 |
- hosts: facthost1 |
| 243 |
tags: [ 'fact_min' ] |
| 244 |
connection: local |
| 245 |
gather_subset: "!all" |
| 246 |
gather_facts: yes |
| 247 |
tasks: |
| 248 |
- name: Test that only retrieving minimal facts work |
| 249 |
assert: |
| 250 |
that: |
| 251 |
# from the min set, which should still collect |
| 252 |
- 'ansible_user_id|default("UNDEF_MIN") != "UNDEF_MIN"' |
| 253 |
- 'ansible_env|default("UNDEF_ENV") != "UNDEF_ENV"' |
| 254 |
# non min facts that are not collected |
| 255 |
- 'ansible_interfaces|default("UNDEF_NET") == "UNDEF_NET"' |
| 256 |
- 'ansible_mounts|default("UNDEF_MOUNT") == "UNDEF_MOUNT"' |
| 257 |
- 'ansible_virtualization_role|default("UNDEF_VIRT") == "UNDEF_VIRT"' |
| 258 |
|
| 259 |
- hosts: facthost2 |
| 260 |
tags: [ 'fact_network' ] |
| 261 |
connection: local |
| 262 |
gather_subset: ["!all", "!min", "network"] |
| 263 |
gather_facts: yes |
| 264 |
tasks: |
| 265 |
- name: Test that retrieving network facts work |
| 266 |
assert: |
| 267 |
that: |
| 268 |
- 'ansible_user_id|default("UNDEF") == "UNDEF"' |
| 269 |
- 'ansible_interfaces|default("UNDEF_NET") != "UNDEF_NET"' |
| 270 |
- 'ansible_mounts|default("UNDEF") == "UNDEF"' |
| 271 |
- 'ansible_virtualization_role|default("UNDEF") == "UNDEF"' |
| 272 |
|
| 273 |
- hosts: facthost3 |
| 274 |
tags: [ 'fact_hardware' ] |
| 275 |
connection: local |
| 276 |
gather_subset: "hardware" |
| 277 |
gather_facts: yes |
| 278 |
tasks: |
| 279 |
- name: Test that retrieving hardware facts work |
| 280 |
assert: |
| 281 |
that: |
| 282 |
- 'ansible_user_id|default("UNDEF_MIN") != "UNDEF_MIN"' |
| 283 |
- 'ansible_interfaces|default("UNDEF_NET") == "UNDEF_NET"' |
| 284 |
- 'ansible_mounts|default("UNDEF_MOUNT") != "UNDEF_MOUNT" or ansible_distribution == "MacOSX"' |
| 285 |
- 'ansible_virtualization_role|default("UNDEF_VIRT") == "UNDEF_VIRT"' |
| 286 |
|
| 287 |
- hosts: facthost4 |
| 288 |
tags: [ 'fact_virtual' ] |
| 289 |
connection: local |
| 290 |
gather_subset: "virtual" |
| 291 |
gather_facts: yes |
| 292 |
tasks: |
| 293 |
- name: Test that retrieving virtualization facts work |
| 294 |
assert: |
| 295 |
that: |
| 296 |
- 'ansible_user_id|default("UNDEF_MIN") != "UNDEF_MIN"' |
| 297 |
- 'ansible_interfaces|default("UNDEF_NET") == "UNDEF_NET"' |
| 298 |
- 'ansible_mounts|default("UNDEF_MOUNT") == "UNDEF_MOUNT"' |
| 299 |
- 'ansible_virtualization_role|default("UNDEF_VIRT") != "UNDEF_VIRT"' |
| 300 |
|
| 301 |
- hosts: facthost5 |
| 302 |
tags: [ 'fact_comma_string' ] |
| 303 |
connection: local |
| 304 |
gather_subset: ["virtual", "network"] |
| 305 |
gather_facts: yes |
| 306 |
tasks: |
| 307 |
- name: Test that retrieving virtualization and network as a string works |
| 308 |
assert: |
| 309 |
that: |
| 310 |
- 'ansible_user_id|default("UNDEF_MIN") != "UNDEF_MIN"' |
| 311 |
- 'ansible_interfaces|default("UNDEF_NET") != "UNDEF_NET"' |
| 312 |
- 'ansible_mounts|default("UNDEF_MOUNT") == "UNDEF_MOUNT"' |
| 313 |
- 'ansible_virtualization_role|default("UNDEF_VIRT") != "UNDEF_VIRT"' |
| 314 |
|
| 315 |
- hosts: facthost6 |
| 316 |
tags: [ 'fact_yaml_list' ] |
| 317 |
connection: local |
| 318 |
gather_subset: |
| 319 |
- virtual |
| 320 |
- network |
| 321 |
gather_facts: yes |
| 322 |
tasks: |
| 323 |
- name: Test that retrieving virtualization and network as a string works |
| 324 |
assert: |
| 325 |
that: |
| 326 |
- 'ansible_user_id|default("UNDEF_MIN") != "UNDEF_MIN"' |
| 327 |
- 'ansible_interfaces|default("UNDEF_NET") != "UNDEF_NET"' |
| 328 |
- 'ansible_mounts|default("UNDEF_MOUNT") == "UNDEF_MOUNT"' |
| 329 |
- 'ansible_virtualization_role|default("UNDEF_VIRT") != "UNDEF_VIRT"' |
| 330 |
|
| 331 |
|
| 332 |
- hosts: facthost7 |
| 333 |
tags: [ 'fact_negation' ] |
| 334 |
connection: local |
| 335 |
gather_subset: "!hardware" |
| 336 |
gather_facts: yes |
| 337 |
tasks: |
| 338 |
- name: Test that negation of fact subsets work |
| 339 |
assert: |
| 340 |
that: |
| 341 |
# network, not collected since it is not in min |
| 342 |
- 'ansible_interfaces|default("UNDEF_NET") == "UNDEF_NET"' |
| 343 |
# not collecting virt, should be undef |
| 344 |
- 'ansible_virtualization_role|default("UNDEF_VIRT") == "UNDEF_VIRT"' |
| 345 |
# mounts/devices are collected by hardware, so should be not collected and undef |
| 346 |
- 'ansible_mounts|default("UNDEF_MOUNT") == "UNDEF_MOUNT"' |
| 347 |
- 'ansible_devices|default("UNDEF_DEVICES") == "UNDEF_DEVICES"' |
| 348 |
# from the min set, which should still collect |
| 349 |
- 'ansible_user_id|default("UNDEF_MIN") != "UNDEF_MIN"' |
| 350 |
- 'ansible_env|default("UNDEF_ENV") != "UNDEF_ENV"' |
| 351 |
|
| 352 |
- hosts: facthost8 |
| 353 |
tags: [ 'fact_mixed_negation_addition' ] |
| 354 |
connection: local |
| 355 |
gather_subset: ["!hardware", "network"] |
| 356 |
gather_facts: yes |
| 357 |
tasks: |
| 358 |
- name: Test that negation and additional subsets work together |
| 359 |
assert: |
| 360 |
that: |
| 361 |
- 'ansible_user_id|default("UNDEF_MIN") != "UNDEF_MIN"' |
| 362 |
- 'ansible_interfaces|default("UNDEF_NET") != "UNDEF_NET"' |
| 363 |
- 'ansible_mounts|default("UNDEF_MOUNT") == "UNDEF_MOUNT"' |
| 364 |
- 'ansible_virtualization_role|default("UNDEF_VIRT") == "UNDEF_VIRT"' |
| 365 |
|
| 366 |
- hosts: facthost14 |
| 367 |
tags: [ 'fact_mixed_negation_addition_min' ] |
| 368 |
connection: local |
| 369 |
gather_subset: ["!all", "!min", "network"] |
| 370 |
gather_facts: yes |
| 371 |
tasks: |
| 372 |
- name: Test that negation and additional subsets work together for min subset |
| 373 |
assert: |
| 374 |
that: |
| 375 |
- 'ansible_user_id|default("UNDEF_MIN") == "UNDEF_MIN"' |
| 376 |
- 'ansible_interfaces|default("UNDEF_NET") != "UNDEF_NET"' |
| 377 |
- 'ansible_default_ipv4|default("UNDEF_DEFAULT_IPV4") != "UNDEF_DEFAULT_IPV4"' |
| 378 |
- 'ansible_all_ipv4_addresses|default("UNDEF_ALL_IPV4") != "UNDEF_ALL_IPV4"' |
| 379 |
- 'ansible_mounts|default("UNDEF_MOUNT") == "UNDEF_MOUNT"' |
| 380 |
- 'ansible_virtualization_role|default("UNDEF_VIRT") == "UNDEF_VIRT"' |
| 381 |
- 'ansible_env|default("UNDEF_ENV") == "UNDEF_ENV"' |
| 382 |
|
| 383 |
- hosts: facthost15 |
| 384 |
tags: [ 'fact_negate_all_min_add_pkg_mgr' ] |
| 385 |
connection: local |
| 386 |
gather_subset: ["!all", "!min", "pkg_mgr"] |
| 387 |
gather_facts: yes |
| 388 |
tasks: |
| 389 |
- name: Test that negation and additional subsets work together for min subset |
| 390 |
assert: |
| 391 |
that: |
| 392 |
# network, not collected since it is not in min |
| 393 |
- 'ansible_interfaces|default("UNDEF_NET") == "UNDEF_NET"' |
| 394 |
# not collecting virt, should be undef |
| 395 |
- 'ansible_virtualization_role|default("UNDEF_VIRT") == "UNDEF_VIRT"' |
| 396 |
# mounts/devices are collected by hardware, so should be not collected and undef |
| 397 |
- 'ansible_mounts|default("UNDEF_MOUNT") == "UNDEF_MOUNT"' |
| 398 |
- 'ansible_devices|default("UNDEF_DEVICES") == "UNDEF_DEVICES"' |
| 399 |
# from the min set, which should not collect |
| 400 |
- 'ansible_user_id|default("UNDEF_MIN") == "UNDEF_MIN"' |
| 401 |
- 'ansible_env|default("UNDEF_ENV") == "UNDEF_ENV"' |
| 402 |
# the pkg_mgr fact we requested explicitly |
| 403 |
- 'ansible_pkg_mgr|default("UNDEF_PKG_MGR") != "UNDEF_PKG_MGR"' |
| 404 |
|
| 405 |
|
| 406 |
- hosts: facthost9 |
| 407 |
tags: [ 'fact_local'] |
| 408 |
connection: local |
| 409 |
gather_facts: no |
| 410 |
tasks: |
| 411 |
- name: Create fact directories |
| 412 |
become: true |
| 413 |
with_items: |
| 414 |
- /etc/ansible/facts.d |
| 415 |
- /tmp/custom_facts.d |
| 416 |
file: |
| 417 |
state: directory |
| 418 |
path: "{{ item }}" |
| 419 |
mode: '0777' |
| 420 |
- name: Deploy local facts |
| 421 |
with_items: |
| 422 |
- path: /etc/ansible/facts.d/testfact.fact |
| 423 |
content: '{ "fact_dir": "default" }' |
| 424 |
- path: /tmp/custom_facts.d/testfact.fact |
| 425 |
content: '{ "fact_dir": "custom" }' |
| 426 |
copy: |
| 427 |
dest: "{{ item.path }}" |
| 428 |
content: "{{ item.content }}" |
| 429 |
|
| 430 |
- hosts: facthost9 |
| 431 |
tags: [ 'fact_local'] |
| 432 |
connection: local |
| 433 |
gather_facts: yes |
| 434 |
tasks: |
| 435 |
- name: Test reading facts from default fact_path |
| 436 |
assert: |
| 437 |
that: |
| 438 |
- 'ansible_local.testfact.fact_dir == "default"' |
| 439 |
|
| 440 |
- hosts: facthost9 |
| 441 |
tags: [ 'fact_local'] |
| 442 |
connection: local |
| 443 |
gather_facts: yes |
| 444 |
fact_path: /tmp/custom_facts.d |
| 445 |
tasks: |
| 446 |
- name: Test reading facts from custom fact_path |
| 447 |
assert: |
| 448 |
that: |
| 449 |
- 'ansible_local.testfact.fact_dir == "custom"' |
| 450 |
|
| 451 |
- hosts: facthost20 |
| 452 |
tags: [ 'fact_facter_ohai' ] |
| 453 |
connection: local |
| 454 |
gather_subset: |
| 455 |
- facter |
| 456 |
- ohai |
| 457 |
gather_facts: yes |
| 458 |
tasks: |
| 459 |
- name: Test that retrieving facter and ohai doesn't fail |
| 460 |
assert: |
| 461 |
# not much to assert here, aside from not crashing, since test images dont have |
| 462 |
# facter/ohai |
| 463 |
that: |
| 464 |
- 'ansible_user_id|default("UNDEF_MIN") != "UNDEF_MIN"' |
| 465 |
|
| 466 |
- hosts: facthost9 |
| 467 |
tags: [ 'fact_file_utils' ] |
| 468 |
connection: local |
| 469 |
gather_facts: false |
| 470 |
tasks: |
| 471 |
- block: |
| 472 |
- name: Ensure get_file_content works when strip=False |
| 473 |
file_utils: |
| 474 |
test: strip |
| 475 |
|
| 476 |
- assert: |
| 477 |
that: |
| 478 |
- ansible_facts.get('etc_passwd_newlines', 0) + 1 == ansible_facts.get('etc_passwd_newlines_unstripped', 0) |
| 479 |
|
| 480 |
- name: Make an empty file |
| 481 |
file: |
| 482 |
path: "{{ output_dir }}/empty_file" |
| 483 |
state: touch |
| 484 |
|
| 485 |
- name: Ensure get_file_content gives default when file is empty |
| 486 |
file_utils: |
| 487 |
test: default |
| 488 |
touch_file: "{{ output_dir }}/empty_file" |
| 489 |
|
| 490 |
- assert: |
| 491 |
that: |
| 492 |
- ansible_facts.get('touch_default') == 'i am a default' |
| 493 |
|
| 494 |
- copy: |
| 495 |
dest: "{{ output_dir }}/1charsep" |
| 496 |
content: "foo:bar:baz:buzz:" |
| 497 |
|
| 498 |
- copy: |
| 499 |
dest: "{{ output_dir }}/2charsep" |
| 500 |
content: "foo::bar::baz::buzz::" |
| 501 |
|
| 502 |
- name: Ensure get_file_lines works as expected with specified 1-char line_sep |
| 503 |
file_utils: |
| 504 |
test: line_sep |
| 505 |
line_sep_file: "{{ output_dir }}/1charsep" |
| 506 |
line_sep_sep: ":" |
| 507 |
|
| 508 |
- assert: |
| 509 |
that: |
| 510 |
- ansible_facts.get('line_sep') == ['foo', 'bar', 'baz', 'buzz'] |
| 511 |
|
| 512 |
- name: Ensure get_file_lines works as expected with specified 1-char line_sep |
| 513 |
file_utils: |
| 514 |
test: line_sep |
| 515 |
line_sep_file: "{{ output_dir }}/2charsep" |
| 516 |
line_sep_sep: "::" |
| 517 |
|
| 518 |
- assert: |
| 519 |
that: |
| 520 |
- ansible_facts.get('line_sep') == ['foo', 'bar', 'baz', 'buzz', ''] |
| 521 |
|
| 522 |
- name: Ensure get_mount_size fails gracefully |
| 523 |
file_utils: |
| 524 |
test: invalid_mountpoint |
| 525 |
|
| 526 |
- assert: |
| 527 |
that: |
| 528 |
- ansible_facts['invalid_mountpoint']|length == 0 |
| 529 |
|
| 530 |
always: |
| 531 |
- name: Remove test files |
| 532 |
file: |
| 533 |
path: "{{ item }}" |
| 534 |
state: absent |
| 535 |
with_items: |
| 536 |
- "{{ output_dir }}/empty_file" |
| 537 |
- "{{ output_dir }}/1charsep" |
| 538 |
- "{{ output_dir }}/2charsep" |