From 14b34c20e5825fca216ae810aa8e50910c90578d Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Mon, 17 Jan 2022 11:30:23 -0700 Subject: [PATCH] Create chrony-online service NetworkManager has a dispatcher which may cause the sources to be marked as disabled. If you don't have any interfaces actually managed with NetworkManager, we need to have a way to ensure that the sources get marked enabled on boot. This change adds a chrony-online service that waits for the network-online.target in order to be able to make chronyd source online. Change-Id: Ib1d91852d281c63b2458fc3c0199a5d5fed17056 --- README.rst | 2 +- files/chrony-online.service | 12 ++++++++++++ tasks/main.yml | 4 ++++ tasks/online.yml | 14 ++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 files/chrony-online.service create mode 100644 tasks/online.yml diff --git a/README.rst b/README.rst index 05132ec..03ab30b 100644 --- a/README.rst +++ b/README.rst @@ -18,7 +18,7 @@ Role Variables - Enable debug option in chrony * - `chrony_role_action` - `all` - - Ansible action when including the role. Should be one of: [all|install|config|upgrade] + - Ansible action when including the role. Should be one of: [all|install|config|upgrade|online] * - `chrony_package_name` - `chrony` - chrony system package name diff --git a/files/chrony-online.service b/files/chrony-online.service new file mode 100644 index 0000000..551174a --- /dev/null +++ b/files/chrony-online.service @@ -0,0 +1,12 @@ +[Unit] +Description=chronyd online sources service +After=network-online.target chronyd.service +Wants=network-online.target chronyd.service + +[Service] +Type=oneshot +ExecStart=/usr/libexec/chrony-helper command online +User=root + +[Install] +WantedBy=multi-user.target diff --git a/tasks/main.yml b/tasks/main.yml index 778539c..840d75b 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -17,3 +17,7 @@ - name: Configure chronyd include_tasks: config.yml when: chrony_role_action in ['all', 'config'] + +- name: Enable online service + include_tasks: online.yml + when: chrony_role_action in ['all', 'online'] diff --git a/tasks/online.yml b/tasks/online.yml new file mode 100644 index 0000000..42459ef --- /dev/null +++ b/tasks/online.yml @@ -0,0 +1,14 @@ +--- +- name: Create chrony-online.service unit file + become: True + copy: + src: files/chrony-online.service + dest: /etc/systemd/system/chrony-online.service + +- name: Enable chrony-online.service + become: True + systemd: + state: started + name: chrony-online.service + enabled: true + daemon-reload: true