timesync.yml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. ---
  2. ### Create groups
  3. - hosts: all
  4. tasks:
  5. - group_by:
  6. key: "virt_{{ ansible_virtualization_role }}"
  7. - hosts: virt_guest
  8. gather_facts: no
  9. tasks:
  10. - group_by:
  11. key: "virtguest_{{ ansible_virtualization_type }}"
  12. # Debugging only
  13. - hosts: localhost
  14. gather_facts: no
  15. tasks:
  16. - debug:
  17. var: groups
  18. ### Hosts: Install/Configure NTP
  19. - hosts:
  20. - virt_NA
  21. - virt_host
  22. gather_facts: no
  23. roles:
  24. - timesync-enabled
  25. ### Container-Guests: Disable timesync!
  26. - hosts:
  27. - virtguest_docker
  28. - virtguest_openvz
  29. - virtguest_linuxvserver
  30. - virtguest_lxc
  31. - virtguest_lxc-libvirt
  32. - virtguest_rkt
  33. - virtguest_uml
  34. - virtguest_systemd-nspawn
  35. - virtguest_container-other
  36. gather_facts: no
  37. roles:
  38. - timesync-disabled
  39. ### KVM-Guests:
  40. # https://s19n.net/articles/2011/kvm_clock.html
  41. - hosts:
  42. - virtguest_kvm
  43. gather_facts: no
  44. pre_tasks:
  45. - command: cat /sys/devices/system/clocksource/clocksource0/current_clocksource
  46. register: clocksource
  47. changed_when: False
  48. # Fail if clocksource is NOT "kvm-clock"
  49. - assert:
  50. that:
  51. - clocksource.stdout == "kvm-clock"
  52. - debug: var=timesync_servers
  53. roles:
  54. - { role: timesync-disabled, when: clocksource.stdout == "kvm-clock" and timesync_servers is not defined }
  55. - { role: timesync-enabled, when: clocksource.stdout != "kvm-clock" or timesync_servers is defined }
  56. ### VMware-Guests:
  57. # Open-VM-Tools: https://blogs.vmware.com/vsphere/2015/09/open-vm-tools-ovt-the-future-of-vmware-tools-for-linux.html
  58. - hosts:
  59. - virtguest_VMware
  60. gather_facts: no
  61. pre_tasks:
  62. - name: Get timesync status
  63. command: vmware-toolbox-cmd timesync status
  64. changed_when: False
  65. register: vmwtbcmd_timesync
  66. ignore_errors: True
  67. - name: Install Open-VM-Tools
  68. package:
  69. name: open-vm-tools
  70. state: present
  71. when: vmwtbcmd_timesync|failed
  72. - name: Get timesync status AGAIN
  73. command: vmware-toolbox-cmd timesync status
  74. changed_when: False
  75. register: vmwtbcmd_timesync
  76. - assert:
  77. that:
  78. - vmwtbcmd_timesync.stdout in ["Enabled", "Disabled"]
  79. roles:
  80. - { role: timesync-disabled, when: vmwtbcmd_timesync.stdout == "Disabled" }
  81. - { role: timesync-enabled, when: vmwtbcmd_timesync.stdout == "Enabled"}
  82. ### Xen-Guests: https://wiki.xen.org/wiki/Xen_FAQ_DomU#How_can_i_synchronize_a_dom0_clock.3F
  83. - hosts:
  84. - virtguest_xen
  85. gather_facts: no
  86. pre_tasks:
  87. - command: cat /proc/sys/xen/independent_wallclock
  88. changed_when: False
  89. register: independent_wallclock
  90. - assert:
  91. that:
  92. - independent_wallclock.stdout == "1"
  93. roles:
  94. - timesync-enabled
  95. ### FIXME
  96. - hosts:
  97. - virtguest_RHEV
  98. - virtguest_virtualbox
  99. - virtguest_VirtualPC
  100. - virtguest_parallels
  101. - virtguest_powervm_lx86
  102. - "virtguest_PR/SM_LPAR"
  103. - virtguest_ibm_systemz
  104. gather_facts: no
  105. tasks:
  106. - fail:
  107. msg: "Not yet implemented"