Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding option to configure RTC changes #10

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ systemd with timesyncd compiled in

## Role Variables

| Name | Default/Required | Description |
|-------------------------------|:---------------------:|-----------------------------------------------------|
| `timesync_timezone` | `Etc/UTC` | Timezone to set (relative to `/usr/share/zoneinfo`) |
| `timesync_ntp_hosts` | | Array of NTP hosts |
| `timesync_fallback_ntp_hosts` | `{0..3}.pool.ntp.org` | Array of fallback NTP hosts |
| Name | Default/Required | Description |
|-------------------------------|:---------------------:|----------------------------------------------------------------------------------|
| `timesync_timezone` | `Etc/UTC` | Timezone to set (relative to `/usr/share/zoneinfo`) |
| `timesync_ntp_hosts` | | Array of NTP hosts |
| `timesync_fallback_ntp_hosts` | `{0..3}.pool.ntp.org` | Array of fallback NTP hosts |
| `timesync_rtc_set` | `auto` | Determines if the RTC will be updated. `auto` will only update if the RTC exists |
| `timesync_rtc_dev` | `/dev/rtc` | The RTC device to be used |

## Dependencies

Expand Down
2 changes: 2 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ timesync_fallback_ntp_hosts:
- 1.pool.ntp.org
- 2.pool.ntp.org
- 3.pool.ntp.org
timesync_rtc_set: auto
timesync_rtc_dev: /dev/rtc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please insert new line at the end of the file.

5 changes: 0 additions & 5 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,3 @@
name: systemd-timesyncd.service
state: restarted
listen: systemd-timesyncd configuration changed

- name: Write adjtime
command: hwclock --systohc
when: ansible_virtualization_role == "host" or ansible_virtualization_role == "NA"
listen: systemd-timesyncd configuration changed
27 changes: 27 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,30 @@
name: systemd-timesyncd.service
enabled: yes
state: started

- name: Flush handlers for restart prior to RTC update
meta: flush_handlers

- name: Check if RTC exists
stat:
path: "{{timesync_rtc_dev}}"
register: rtc_dev
when: timesync_rtc_set == "auto"

- name: "Evaluate RTC auto update"
set_fact:
timesync_rtc_set: true
when: timesync_rtc_set == "auto" and rtc_dev.stat.exists and rtc.dev.stat.writeable and (ansible_virtualization_role == "host" or ansible_virtualization_role == "NA")

- name: Wait for time to synchronize
shell: "timedatectl | grep 'NTP synchronized' | cut -d' ' -f3"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I run timedatectl on any on my machines, there is no such output NTP synchronized.
My output is:

               Local time: <timestamp>
           Universal time: <timestamp>
                 RTC time: <timestamp>
                Time zone: <tz>
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

Can you explain under which circumstances the output NTP synchronized will occur?

register: synchronized
retries: 5
delay: 5
until: synchronized.stdout == "yes"
when: timesync_rtc_set == true

- name: Write adjtime
command: "hwclock --systohc --rtc={{timesync_rtc_dev}}"
when: timesync_rtc_set == true