| 1 |
--- |
| 2 |
# Copyright (c) Ansible Project |
| 3 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 4 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
|
| 6 |
## |
| 7 |
## test setting timezone, idempotency and checkmode |
| 8 |
## |
| 9 |
|
| 10 |
- name: set timezone to Australia/Brisbane (checkmode) |
| 11 |
timezone: |
| 12 |
name: Australia/Brisbane |
| 13 |
check_mode: true |
| 14 |
register: timezone_set_checkmode |
| 15 |
|
| 16 |
- name: ensure timezone reported as changed in checkmode |
| 17 |
assert: |
| 18 |
that: |
| 19 |
- timezone_set_checkmode.changed |
| 20 |
- timezone_set_checkmode.diff.after.name == 'Australia/Brisbane' |
| 21 |
- timezone_set_checkmode.diff.before.name == 'Etc/UTC' |
| 22 |
|
| 23 |
- name: ensure checkmode didn't change the timezone |
| 24 |
command: cmp /etc/localtime /usr/share/zoneinfo/Australia/Brisbane |
| 25 |
register: result |
| 26 |
failed_when: result is not failed |
| 27 |
changed_when: false |
| 28 |
|
| 29 |
- name: ensure that checkmode didn't update the timezone in the config file |
| 30 |
command: egrep '^(TIME)?ZONE="Etc/UTC"' {{ timezone_config_file }} |
| 31 |
when: |
| 32 |
- ansible_facts.service_mgr != 'systemd' |
| 33 |
- ansible_facts.os_family == 'RedHat' |
| 34 |
|
| 35 |
- name: ensure that checkmode didn't update the timezone in the config file |
| 36 |
command: egrep '^Etc/UTC' {{ timezone_config_file }} |
| 37 |
when: |
| 38 |
- ansible_facts.service_mgr != 'systemd' |
| 39 |
- ansible_facts.os_family == 'Debian' |
| 40 |
|
| 41 |
- name: set timezone to Australia/Brisbane |
| 42 |
timezone: |
| 43 |
name: Australia/Brisbane |
| 44 |
register: timezone_set |
| 45 |
|
| 46 |
- name: ensure timezone changed |
| 47 |
assert: |
| 48 |
that: |
| 49 |
- timezone_set.changed |
| 50 |
- timezone_set.diff.after.name == 'Australia/Brisbane' |
| 51 |
- timezone_set.diff.before.name == 'Etc/UTC' |
| 52 |
|
| 53 |
- name: ensure that the timezone is actually set |
| 54 |
command: cmp /etc/localtime /usr/share/zoneinfo/Australia/Brisbane |
| 55 |
changed_when: false |
| 56 |
|
| 57 |
- name: ensure that the timezone is updated in the config file |
| 58 |
command: egrep '^(TIME)?ZONE="Australia/Brisbane"' {{ timezone_config_file }} |
| 59 |
when: |
| 60 |
- ansible_facts.service_mgr != 'systemd' |
| 61 |
- ansible_facts.os_family == 'RedHat' |
| 62 |
|
| 63 |
- name: ensure that the timezone is updated in the config file |
| 64 |
command: egrep '^Australia/Brisbane' {{ timezone_config_file }} |
| 65 |
when: |
| 66 |
- ansible_facts.service_mgr != 'systemd' |
| 67 |
- ansible_facts.os_family == 'Debian' |
| 68 |
|
| 69 |
- name: set timezone to Australia/Brisbane again |
| 70 |
timezone: |
| 71 |
name: Australia/Brisbane |
| 72 |
register: timezone_again |
| 73 |
|
| 74 |
- name: ensure timezone idempotency |
| 75 |
assert: |
| 76 |
that: |
| 77 |
- not timezone_again.changed |
| 78 |
|
| 79 |
- name: set timezone to Australia/Brisbane again in checkmode |
| 80 |
timezone: |
| 81 |
name: Australia/Brisbane |
| 82 |
register: timezone_again_checkmode |
| 83 |
|
| 84 |
- name: set timezone idempotency (checkmode) |
| 85 |
assert: |
| 86 |
that: |
| 87 |
- not timezone_again_checkmode.changed |
| 88 |
|
| 89 |
## |
| 90 |
## tests for same timezones with different names |
| 91 |
## |
| 92 |
|
| 93 |
- name: check dpkg-reconfigure |
| 94 |
shell: type dpkg-reconfigure |
| 95 |
register: check_dpkg_reconfigure |
| 96 |
ignore_errors: true |
| 97 |
changed_when: false |
| 98 |
|
| 99 |
- name: check timedatectl |
| 100 |
shell: type timedatectl && timedatectl |
| 101 |
register: check_timedatectl |
| 102 |
ignore_errors: true |
| 103 |
changed_when: false |
| 104 |
|
| 105 |
- block: |
| 106 |
- name: set timezone to Etc/UTC |
| 107 |
timezone: |
| 108 |
name: Etc/UTC |
| 109 |
|
| 110 |
- name: change timezone from Etc/UTC to UTC |
| 111 |
timezone: |
| 112 |
name: UTC |
| 113 |
register: timezone_etcutc_to_utc |
| 114 |
|
| 115 |
- name: check timezone changed from Etc/UTC to UTC |
| 116 |
assert: |
| 117 |
that: |
| 118 |
- timezone_etcutc_to_utc.changed |
| 119 |
- timezone_etcutc_to_utc.diff.before.name == 'Etc/UTC' |
| 120 |
- timezone_etcutc_to_utc.diff.after.name == 'UTC' |
| 121 |
|
| 122 |
- name: change timezone from UTC to Etc/UTC |
| 123 |
timezone: |
| 124 |
name: Etc/UTC |
| 125 |
register: timezone_utc_to_etcutc |
| 126 |
|
| 127 |
- name: check timezone changed from UTC to Etc/UTC |
| 128 |
assert: |
| 129 |
that: |
| 130 |
- timezone_utc_to_etcutc.changed |
| 131 |
- timezone_utc_to_etcutc.diff.before.name == 'UTC' |
| 132 |
- timezone_utc_to_etcutc.diff.after.name == 'Etc/UTC' |
| 133 |
|
| 134 |
when: |
| 135 |
# FIXME: Due to the bug of the dpkg-reconfigure, those tests failed on non-systemd debian |
| 136 |
- check_dpkg_reconfigure.rc != 0 or check_timedatectl.rc == 0 |
| 137 |
|
| 138 |
## |
| 139 |
## no systemd tests for timezone |
| 140 |
## |
| 141 |
|
| 142 |
- block: |
| 143 |
## |
| 144 |
## test with empty config file |
| 145 |
## |
| 146 |
|
| 147 |
- name: empty config file |
| 148 |
command: cp /dev/null {{ timezone_config_file }} |
| 149 |
|
| 150 |
- name: set timezone to Europe/Belgrade (empty config file) |
| 151 |
timezone: |
| 152 |
name: Europe/Belgrade |
| 153 |
register: timezone_empty_conf |
| 154 |
|
| 155 |
- name: check if timezone set (empty config file) |
| 156 |
assert: |
| 157 |
that: |
| 158 |
- timezone_empty_conf.changed |
| 159 |
- timezone_empty_conf.diff.after.name == 'Europe/Belgrade' |
| 160 |
- timezone_empty_conf.diff.before.name == 'n/a' |
| 161 |
|
| 162 |
- name: check if the timezone is actually set (empty config file) |
| 163 |
command: cmp /etc/localtime /usr/share/zoneinfo/Europe/Belgrade |
| 164 |
changed_when: false |
| 165 |
|
| 166 |
|
| 167 |
## |
| 168 |
## test with deleted config file |
| 169 |
## |
| 170 |
|
| 171 |
- name: remove config file |
| 172 |
file: |
| 173 |
path: '{{ timezone_config_file }}' |
| 174 |
state: absent |
| 175 |
|
| 176 |
- name: set timezone to Europe/Belgrade (no config file) |
| 177 |
timezone: |
| 178 |
name: Europe/Belgrade |
| 179 |
register: timezone_missing_conf |
| 180 |
|
| 181 |
- name: check if timezone set (no config file) |
| 182 |
assert: |
| 183 |
that: |
| 184 |
- timezone_missing_conf.changed |
| 185 |
- timezone_missing_conf.diff.after.name == 'Europe/Belgrade' |
| 186 |
- timezone_missing_conf.diff.before.name == 'n/a' |
| 187 |
|
| 188 |
- name: check if the timezone is actually set (no config file) |
| 189 |
command: cmp /etc/localtime /usr/share/zoneinfo/Europe/Belgrade |
| 190 |
changed_when: false |
| 191 |
|
| 192 |
|
| 193 |
## |
| 194 |
## test with /etc/localtime as symbolic link to a zoneinfo file |
| 195 |
## |
| 196 |
|
| 197 |
- name: create symlink /etc/locatime -> /usr/share/zoneinfo/Etc/UTC |
| 198 |
file: |
| 199 |
src: /usr/share/zoneinfo/Etc/UTC |
| 200 |
dest: /etc/localtime |
| 201 |
state: link |
| 202 |
force: true |
| 203 |
|
| 204 |
- name: set timezone to Europe/Belgrade (over symlink) |
| 205 |
timezone: |
| 206 |
name: Europe/Belgrade |
| 207 |
register: timezone_symllink |
| 208 |
|
| 209 |
- name: check if timezone set (over symlink) |
| 210 |
assert: |
| 211 |
that: |
| 212 |
- timezone_symllink.changed |
| 213 |
- timezone_symllink.diff.after.name == 'Europe/Belgrade' |
| 214 |
- timezone_symllink.diff.before.name == 'Etc/UTC' |
| 215 |
|
| 216 |
- name: check if the timezone is actually set (over symlink) |
| 217 |
command: cmp /etc/localtime /usr/share/zoneinfo/Europe/Belgrade |
| 218 |
changed_when: false |
| 219 |
|
| 220 |
|
| 221 |
## |
| 222 |
## test with /etc/localtime as broken symbolic link |
| 223 |
## |
| 224 |
|
| 225 |
- name: set timezone to a broken symlink |
| 226 |
file: |
| 227 |
src: /tmp/foo |
| 228 |
dest: /etc/localtime |
| 229 |
state: link |
| 230 |
force: true |
| 231 |
|
| 232 |
- name: set timezone to Europe/Belgrade (over broken symlink) |
| 233 |
timezone: |
| 234 |
name: Europe/Belgrade |
| 235 |
register: timezone_symllink_broken |
| 236 |
|
| 237 |
- name: check if timezone set (over broken symlink) |
| 238 |
assert: |
| 239 |
that: |
| 240 |
- timezone_symllink_broken.changed |
| 241 |
- timezone_symllink_broken.diff.after.name == 'Europe/Belgrade' |
| 242 |
- timezone_symllink_broken.diff.before.name == 'n/a' |
| 243 |
|
| 244 |
- name: check if the timezone is actually set (over broken symlink) |
| 245 |
command: cmp /etc/localtime /usr/share/zoneinfo/Europe/Belgrade |
| 246 |
changed_when: false |
| 247 |
|
| 248 |
|
| 249 |
## |
| 250 |
## test with /etc/localtime set manually using copy |
| 251 |
## |
| 252 |
|
| 253 |
- name: set timezone manually by coping zone info file to /etc/localtime |
| 254 |
copy: |
| 255 |
src: /usr/share/zoneinfo/Etc/UTC |
| 256 |
dest: /etc/localtime |
| 257 |
remote_src: true |
| 258 |
|
| 259 |
- name: set timezone to Europe/Belgrade (over copied file) |
| 260 |
timezone: |
| 261 |
name: Europe/Belgrade |
| 262 |
register: timezone_copied |
| 263 |
|
| 264 |
- name: check if timezone set (over copied file) |
| 265 |
assert: |
| 266 |
that: |
| 267 |
- timezone_copied.changed |
| 268 |
- timezone_copied.diff.after.name == 'Europe/Belgrade' |
| 269 |
- timezone_copied.diff.before.name == 'n/a' |
| 270 |
|
| 271 |
- name: check if the timezone is actually set (over copied file) |
| 272 |
command: cmp /etc/localtime /usr/share/zoneinfo/Europe/Belgrade |
| 273 |
changed_when: false |
| 274 |
when: |
| 275 |
- ansible_facts.service_mgr != 'systemd' |
| 276 |
- timezone_config_file is defined |
| 277 |
|
| 278 |
|
| 279 |
#### |
| 280 |
#### hwclock tests |
| 281 |
#### |
| 282 |
|
| 283 |
- name: check if hwclock is supported in the environment |
| 284 |
command: hwclock --test |
| 285 |
register: hwclock_test |
| 286 |
ignore_errors: true |
| 287 |
|
| 288 |
- name: check if timedatectl works in the environment |
| 289 |
command: timedatectl |
| 290 |
register: timedatectl_test |
| 291 |
ignore_errors: true |
| 292 |
|
| 293 |
- name: |
| 294 |
set_fact: |
| 295 |
hwclock_supported: '{{ hwclock_test is successful or (timedatectl_test is successful and "RTC time: n/a" not in timedatectl_test.stdout) }}' |
| 296 |
## |
| 297 |
## test set hwclock, idempotency and checkmode |
| 298 |
## |
| 299 |
|
| 300 |
- block: |
| 301 |
- name: set hwclock to local |
| 302 |
timezone: |
| 303 |
hwclock: local |
| 304 |
|
| 305 |
- name: set hwclock to UTC (checkmode) |
| 306 |
timezone: |
| 307 |
hwclock: UTC |
| 308 |
check_mode: true |
| 309 |
register: hwclock_set_checkmode |
| 310 |
|
| 311 |
- name: ensure hwclock reported as changed (checkmode) |
| 312 |
assert: |
| 313 |
that: |
| 314 |
- hwclock_set_checkmode.changed |
| 315 |
- hwclock_set_checkmode.diff.after.hwclock == 'UTC' |
| 316 |
- hwclock_set_checkmode.diff.before.hwclock == 'local' |
| 317 |
|
| 318 |
- block: |
| 319 |
- name: ensure that checkmode didn't update hwclock in /etc/adjtime |
| 320 |
command: grep ^UTC /etc/adjtime |
| 321 |
register: result |
| 322 |
failed_when: result is not failed |
| 323 |
|
| 324 |
- name: ensure that checkmode didn't update hwclock the config file |
| 325 |
command: grep ^UTC=no {{ hwclock_config_file }} |
| 326 |
when: ansible_facts.service_mgr != 'systemd' |
| 327 |
|
| 328 |
- name: set hwclock to UTC |
| 329 |
timezone: |
| 330 |
hwclock: UTC |
| 331 |
register: hwclock_set |
| 332 |
|
| 333 |
- name: ensure hwclock changed |
| 334 |
assert: |
| 335 |
that: |
| 336 |
- hwclock_set.changed |
| 337 |
- hwclock_set.diff.after.hwclock == 'UTC' |
| 338 |
- hwclock_set.diff.before.hwclock == 'local' |
| 339 |
|
| 340 |
- block: |
| 341 |
- name: ensure that hwclock is updated in /etc/adjtime |
| 342 |
command: grep ^UTC /etc/adjtime |
| 343 |
|
| 344 |
- name: ensure that hwclock is updated in the config file |
| 345 |
command: grep ^UTC=yes {{ hwclock_config_file }} |
| 346 |
when: ansible_facts.service_mgr != 'systemd' |
| 347 |
|
| 348 |
- name: set hwclock to RTC again |
| 349 |
timezone: |
| 350 |
hwclock: UTC |
| 351 |
register: hwclock_again |
| 352 |
|
| 353 |
- name: set hwclock idempotency |
| 354 |
assert: |
| 355 |
that: |
| 356 |
- not hwclock_again.changed |
| 357 |
|
| 358 |
- name: set hwclock to RTC again (checkmode) |
| 359 |
timezone: |
| 360 |
hwclock: UTC |
| 361 |
check_mode: true |
| 362 |
register: hwclock_again_checkmode |
| 363 |
|
| 364 |
- name: set hwclock idempotency (checkmode) |
| 365 |
assert: |
| 366 |
that: |
| 367 |
- not hwclock_again_checkmode.changed |
| 368 |
|
| 369 |
|
| 370 |
## |
| 371 |
## no systemd tests for hwclock |
| 372 |
## |
| 373 |
|
| 374 |
- block: |
| 375 |
## |
| 376 |
## test set hwclock with both /etc/adjtime and conf file deleted |
| 377 |
## |
| 378 |
|
| 379 |
- name: remove /etc/adjtime and conf file |
| 380 |
file: |
| 381 |
path: '{{ item }}' |
| 382 |
state: absent |
| 383 |
with_items: |
| 384 |
- /etc/adjtime |
| 385 |
- '{{ hwclock_config_file }}' |
| 386 |
|
| 387 |
- name: set hwclock to UTC with deleted /etc/adjtime and conf file |
| 388 |
timezone: |
| 389 |
hwclock: UTC |
| 390 |
register: hwclock_set_utc_deleted_adjtime_and_conf |
| 391 |
|
| 392 |
- name: ensure hwclock changed with deleted /etc/adjtime and conf |
| 393 |
assert: |
| 394 |
that: |
| 395 |
- hwclock_set_utc_deleted_adjtime_and_conf.changed |
| 396 |
- hwclock_set_utc_deleted_adjtime_and_conf.diff.after.hwclock == 'UTC' |
| 397 |
- hwclock_set_utc_deleted_adjtime_and_conf.diff.before.hwclock == 'n/a' |
| 398 |
|
| 399 |
|
| 400 |
## |
| 401 |
## test set hwclock with /etc/adjtime deleted |
| 402 |
## |
| 403 |
|
| 404 |
- name: remove /etc/adjtime |
| 405 |
file: |
| 406 |
path: '{{ item }}' |
| 407 |
state: absent |
| 408 |
with_items: |
| 409 |
- /etc/adjtime |
| 410 |
|
| 411 |
- name: set hwclock to UTC with deleted /etc/adjtime |
| 412 |
timezone: |
| 413 |
hwclock: UTC |
| 414 |
register: hwclock_set_utc_deleted_adjtime_utc |
| 415 |
|
| 416 |
- name: ensure hwclock changed with deleted /etc/adjtime |
| 417 |
assert: |
| 418 |
that: |
| 419 |
- not hwclock_set_utc_deleted_adjtime_utc.changed |
| 420 |
- hwclock_set_utc_deleted_adjtime_utc.diff.after.hwclock == 'UTC' |
| 421 |
- hwclock_set_utc_deleted_adjtime_utc.diff.before.hwclock == 'UTC' |
| 422 |
|
| 423 |
- name: set hwclock to LOCAL with deleted /etc/adjtime |
| 424 |
timezone: |
| 425 |
hwclock: local |
| 426 |
register: hwclock_set_local_deleted_adjtime_local |
| 427 |
|
| 428 |
- name: ensure hwclock changed to LOCAL with deleted /etc/adjtime |
| 429 |
assert: |
| 430 |
that: |
| 431 |
- hwclock_set_local_deleted_adjtime_local.changed |
| 432 |
- hwclock_set_local_deleted_adjtime_local.diff.after.hwclock == 'local' |
| 433 |
- hwclock_set_local_deleted_adjtime_local.diff.before.hwclock == 'UTC' |
| 434 |
|
| 435 |
|
| 436 |
## |
| 437 |
## test set hwclock with conf file deleted |
| 438 |
## |
| 439 |
|
| 440 |
- name: remove conf file |
| 441 |
file: |
| 442 |
path: '{{ item }}' |
| 443 |
state: absent |
| 444 |
with_items: |
| 445 |
- '{{ hwclock_config_file }}' |
| 446 |
|
| 447 |
- name: set hwclock to UTC with deleted conf |
| 448 |
timezone: |
| 449 |
hwclock: UTC |
| 450 |
register: hwclock_set_utc_deleted_conf |
| 451 |
|
| 452 |
- name: ensure hwclock changed with deleted /etc/adjtime |
| 453 |
assert: |
| 454 |
that: |
| 455 |
- hwclock_set_utc_deleted_conf.changed |
| 456 |
- hwclock_set_utc_deleted_conf.diff.after.hwclock == 'UTC' |
| 457 |
- hwclock_set_utc_deleted_conf.diff.before.hwclock == 'n/a' |
| 458 |
|
| 459 |
|
| 460 |
## |
| 461 |
## test set hwclock with /etc/adjtime missing UTC/LOCAL strings |
| 462 |
## |
| 463 |
|
| 464 |
- name: create /etc/adjtime without UTC/LOCAL |
| 465 |
copy: |
| 466 |
content: '0.0 0 0\n0' |
| 467 |
dest: /etc/adjtime |
| 468 |
|
| 469 |
- name: set hwclock to UTC with broken /etc/adjtime |
| 470 |
timezone: |
| 471 |
hwclock: UTC |
| 472 |
register: hwclock_set_utc_broken_adjtime |
| 473 |
|
| 474 |
- name: ensure hwclock doesn't report changed with broken /etc/adjtime |
| 475 |
assert: |
| 476 |
that: |
| 477 |
- not hwclock_set_utc_broken_adjtime.changed |
| 478 |
- hwclock_set_utc_broken_adjtime.diff.after.hwclock == 'UTC' |
| 479 |
- hwclock_set_utc_broken_adjtime.diff.before.hwclock == 'UTC' |
| 480 |
|
| 481 |
- name: set hwclock to LOCAL with broken /etc/adjtime |
| 482 |
timezone: |
| 483 |
hwclock: local |
| 484 |
register: hwclock_set_local_broken_adjtime |
| 485 |
|
| 486 |
- name: ensure hwclock changed to LOCAL with broken /etc/adjtime |
| 487 |
assert: |
| 488 |
that: |
| 489 |
- hwclock_set_local_broken_adjtime.changed |
| 490 |
- hwclock_set_local_broken_adjtime.diff.after.hwclock == 'local' |
| 491 |
- hwclock_set_local_broken_adjtime.diff.before.hwclock == 'UTC' |
| 492 |
when: |
| 493 |
- ansible_facts.service_mgr != 'systemd' |
| 494 |
- hwclock_config_file is defined |
| 495 |
|
| 496 |
#### |
| 497 |
#### timezone + hwclock tests |
| 498 |
#### |
| 499 |
|
| 500 |
## |
| 501 |
## test set timezone and hwclock, idempotency and checkmode |
| 502 |
## |
| 503 |
|
| 504 |
- name: set timezone to Etc/UTC and hwclock to local |
| 505 |
timezone: |
| 506 |
name: Etc/UTC |
| 507 |
hwclock: local |
| 508 |
|
| 509 |
- name: set timezone to Europe/Belgrade and hwclock to UTC (checkmode) |
| 510 |
timezone: |
| 511 |
name: Europe/Belgrade |
| 512 |
hwclock: UTC |
| 513 |
check_mode: true |
| 514 |
register: tzclock_set_checkmode |
| 515 |
|
| 516 |
- name: ensure timezone and hwclock reported as changed in checkmode |
| 517 |
assert: |
| 518 |
that: |
| 519 |
- tzclock_set_checkmode.changed |
| 520 |
- tzclock_set_checkmode.diff.after.name == 'Europe/Belgrade' |
| 521 |
- tzclock_set_checkmode.diff.before.name == 'Etc/UTC' |
| 522 |
- tzclock_set_checkmode.diff.after.hwclock == 'UTC' |
| 523 |
- tzclock_set_checkmode.diff.before.hwclock == 'local' |
| 524 |
|
| 525 |
- name: ensure checkmode didn't change the timezone |
| 526 |
command: cmp /etc/localtime /usr/share/zoneinfo/Australia/Brisbane |
| 527 |
register: result |
| 528 |
failed_when: result is not failed |
| 529 |
changed_when: false |
| 530 |
|
| 531 |
- block: |
| 532 |
- name: ensure that checkmode didn't update the timezone in the config file |
| 533 |
command: egrep '^(TIME)?ZONE="Etc/UTC"' {{ timezone_config_file }} |
| 534 |
when: |
| 535 |
- ansible_facts.os_family == 'RedHat' |
| 536 |
|
| 537 |
- name: ensure that checkmode didn't update the timezone in the config file |
| 538 |
command: egrep '^Etc/UTC' {{ timezone_config_file }} |
| 539 |
when: |
| 540 |
- ansible_facts.os_family == 'Debian' |
| 541 |
|
| 542 |
- name: ensure that checkmode didn't update hwclock in /etc/adjtime |
| 543 |
command: grep ^UTC /etc/adjtime |
| 544 |
register: result |
| 545 |
failed_when: result is not failed |
| 546 |
|
| 547 |
- name: ensure that checkmode didn't update hwclock the config file |
| 548 |
command: grep ^UTC=no {{ hwclock_config_file }} |
| 549 |
when: ansible_facts.service_mgr != 'systemd' |
| 550 |
|
| 551 |
- name: set timezone to Europe/Belgrade and hwclock to UTC |
| 552 |
timezone: |
| 553 |
name: Europe/Belgrade |
| 554 |
hwclock: UTC |
| 555 |
register: tzclock_set |
| 556 |
|
| 557 |
- name: ensure timezone and hwclock changed |
| 558 |
assert: |
| 559 |
that: |
| 560 |
- tzclock_set.changed |
| 561 |
- tzclock_set.diff.after.name == 'Europe/Belgrade' |
| 562 |
- tzclock_set.diff.before.name == 'Etc/UTC' |
| 563 |
- tzclock_set.diff.after.hwclock == 'UTC' |
| 564 |
- tzclock_set.diff.before.hwclock == 'local' |
| 565 |
|
| 566 |
- name: ensure that the timezone is actually set |
| 567 |
command: cmp /etc/localtime /usr/share/zoneinfo/Europe/Belgrade |
| 568 |
changed_when: false |
| 569 |
|
| 570 |
- block: |
| 571 |
- name: ensure that the timezone is updated in the config file |
| 572 |
command: egrep '^(TIME)?ZONE="Europe/Belgrade"' {{ timezone_config_file }} |
| 573 |
when: |
| 574 |
- ansible_facts.os_family == 'RedHat' |
| 575 |
|
| 576 |
- name: ensure that the timezone is updated in the config file |
| 577 |
command: egrep 'Europe/Belgrade' {{ timezone_config_file }} |
| 578 |
when: |
| 579 |
- ansible_facts.os_family == 'Debian' |
| 580 |
|
| 581 |
- name: ensure that hwclock is updated in /etc/adjtime |
| 582 |
command: grep ^UTC /etc/adjtime |
| 583 |
|
| 584 |
- name: ensure that hwclock is updated in the config file |
| 585 |
command: grep ^UTC=yes {{ hwclock_config_file }} |
| 586 |
when: ansible_facts.service_mgr != 'systemd' |
| 587 |
|
| 588 |
- name: set timezone to Europe/Belgrade and hwclock to UTC again |
| 589 |
timezone: |
| 590 |
name: Europe/Belgrade |
| 591 |
hwclock: UTC |
| 592 |
register: tzclock_set_again |
| 593 |
|
| 594 |
- name: set timezone and hwclock idempotency |
| 595 |
assert: |
| 596 |
that: |
| 597 |
- not tzclock_set_again.changed |
| 598 |
|
| 599 |
- name: set timezone to Europe/Belgrade and hwclock to UTC again (checkmode) |
| 600 |
timezone: |
| 601 |
name: Europe/Belgrade |
| 602 |
hwclock: UTC |
| 603 |
register: tzclock_set_again_checkmode |
| 604 |
|
| 605 |
- name: set timezone and hwclock idempotency in checkmode |
| 606 |
assert: |
| 607 |
that: |
| 608 |
- not tzclock_set_again_checkmode.changed |
| 609 |
|
| 610 |
when: |
| 611 |
- ansible_facts.system == 'Linux' |
| 612 |
- hwclock_supported |