Add tasks for run and sync to chrony role
- Moves some of the tasks from config.yml that are actually used to run the chronyd into a new dedicated run.yml tasks file. - Adds a sync.yml with tasks for actually syncing using chronyc. - Adds some install tasks to install.yml to disable ntpd in case it is running as it's not compatible when chronyd is also running. - Refactors the distro variable loading into a common tasks vars.yml that can be reused by the other tasks files - Adds a symbolic link 'chrony' to the top level directory of the project, since the role is named 'chrony', and ansible searches for a directory with that name. Signed-off-by: James Slagle <jslagle@redhat.com> Change-Id: I673ce4fc17dd98aa251fdffce73bf9a096aad6fb
This commit is contained in:
parent
7ccf873c82
commit
9528e8a0b7
@ -1,4 +1,23 @@
|
|||||||
---
|
---
|
||||||
|
# Copyright 2022 Red Hat, Inc.
|
||||||
|
# # All Rights Reserved.
|
||||||
|
# #
|
||||||
|
# # Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# # not use this file except in compliance with the License. You may obtain
|
||||||
|
# # a copy of the License at
|
||||||
|
# #
|
||||||
|
# # http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
# #
|
||||||
|
# # Unless required by applicable law or agreed to in writing, software
|
||||||
|
# # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# # License for the specific language governing permissions and limitations
|
||||||
|
# # under the License.
|
||||||
|
|
||||||
|
|
||||||
|
- name: Load distro-specific variables
|
||||||
|
include_tasks: vars.yml
|
||||||
|
|
||||||
- name: Install chrony configuration file
|
- name: Install chrony configuration file
|
||||||
template:
|
template:
|
||||||
src: chrony.conf.j2
|
src: chrony.conf.j2
|
||||||
@ -8,23 +27,3 @@
|
|||||||
mode: 0644
|
mode: 0644
|
||||||
register: chrony_config
|
register: chrony_config
|
||||||
notify: Restart chronyd
|
notify: Restart chronyd
|
||||||
|
|
||||||
- name: Ensure chronyd is running
|
|
||||||
service:
|
|
||||||
enabled: "{{ (chrony_service_state|default('started') in ['running', 'started']) |bool }}"
|
|
||||||
name: "{{ chrony_service_name }}"
|
|
||||||
state: "{{ chrony_service_state|default('started') }}"
|
|
||||||
when: chrony_manage_service|bool
|
|
||||||
|
|
||||||
# ansible sometimes ignores handlers when invoked elsewhere. Since we will
|
|
||||||
# likely want to restart chrony after a configuration update, let's do it here
|
|
||||||
# always. The handler will still trigger for upgrades/updates later as well.
|
|
||||||
# This won't have any effect if chrony_manage_service is set to false.
|
|
||||||
# See also https://github.com/ansible/ansible/issues/37512
|
|
||||||
- name: Force chronyd restart
|
|
||||||
service:
|
|
||||||
name: "{{ chrony_service_name }}"
|
|
||||||
state: restarted
|
|
||||||
when:
|
|
||||||
- chrony_manage_service|bool
|
|
||||||
- chrony_config.changed
|
|
||||||
|
@ -1,4 +1,38 @@
|
|||||||
---
|
---
|
||||||
|
# Copyright 2022 Red Hat, Inc.
|
||||||
|
# # All Rights Reserved.
|
||||||
|
# #
|
||||||
|
# # Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# # not use this file except in compliance with the License. You may obtain
|
||||||
|
# # a copy of the License at
|
||||||
|
# #
|
||||||
|
# # http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
# #
|
||||||
|
# # Unless required by applicable law or agreed to in writing, software
|
||||||
|
# # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# # License for the specific language governing permissions and limitations
|
||||||
|
# # under the License.
|
||||||
|
|
||||||
|
|
||||||
|
- name: Load distro-specific variables
|
||||||
|
include_tasks: vars.yml
|
||||||
|
|
||||||
|
- name: Check for NTP service
|
||||||
|
shell: systemctl is-active ntpd.service || systemctl is-enabled ntpd.service
|
||||||
|
failed_when: false
|
||||||
|
register: ntp_service_check
|
||||||
|
|
||||||
|
- name: Disable NTP before configuring Chrony
|
||||||
|
service:
|
||||||
|
name: ntpd
|
||||||
|
state: stopped
|
||||||
|
enabled: false
|
||||||
|
when:
|
||||||
|
- not ansible_check_mode
|
||||||
|
- ntp_service_check.rc is defined
|
||||||
|
- ntp_service_check.rc == 0
|
||||||
|
|
||||||
- name: Install chronyd package
|
- name: Install chronyd package
|
||||||
package:
|
package:
|
||||||
name: "{{ chrony_package_name }}"
|
name: "{{ chrony_package_name }}"
|
||||||
|
@ -1,10 +1,21 @@
|
|||||||
---
|
---
|
||||||
|
# Copyright 2022 Red Hat, Inc.
|
||||||
|
# # All Rights Reserved.
|
||||||
|
# #
|
||||||
|
# # Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# # not use this file except in compliance with the License. You may obtain
|
||||||
|
# # a copy of the License at
|
||||||
|
# #
|
||||||
|
# # http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
# #
|
||||||
|
# # Unless required by applicable law or agreed to in writing, software
|
||||||
|
# # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# # License for the specific language governing permissions and limitations
|
||||||
|
# # under the License.
|
||||||
|
|
||||||
- name: Load distro-specific variables
|
- name: Load distro-specific variables
|
||||||
include_vars: "{{ item }}"
|
include_tasks: vars.yml
|
||||||
with_first_found:
|
|
||||||
- "{{ ansible_facts['distribution'] }}.yml"
|
|
||||||
- "{{ ansible_facts['os_family'] }}.yml"
|
|
||||||
- default.yml
|
|
||||||
|
|
||||||
- name: Install chronyd
|
- name: Install chronyd
|
||||||
include_tasks: install.yml
|
include_tasks: install.yml
|
||||||
@ -18,6 +29,14 @@
|
|||||||
include_tasks: config.yml
|
include_tasks: config.yml
|
||||||
when: chrony_role_action in ['all', 'config']
|
when: chrony_role_action in ['all', 'config']
|
||||||
|
|
||||||
|
- name: Run chronyd
|
||||||
|
include_tasks: run.yml
|
||||||
|
when: chrony_role_action in ['all', 'config', 'run']
|
||||||
|
|
||||||
- name: Enable online service
|
- name: Enable online service
|
||||||
include_tasks: online.yml
|
include_tasks: online.yml
|
||||||
when: chrony_role_action in ['all', 'online']
|
when: chrony_role_action in ['all', 'online']
|
||||||
|
|
||||||
|
- name: Sync chronyc
|
||||||
|
include_tasks: sync.yml
|
||||||
|
when: chrony_role_action in ['all', 'sync']
|
||||||
|
39
tasks/run.yml
Normal file
39
tasks/run.yml
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
---
|
||||||
|
# Copyright 2022 Red Hat, Inc.
|
||||||
|
# # All Rights Reserved.
|
||||||
|
# #
|
||||||
|
# # Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# # not use this file except in compliance with the License. You may obtain
|
||||||
|
# # a copy of the License at
|
||||||
|
# #
|
||||||
|
# # http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
# #
|
||||||
|
# # Unless required by applicable law or agreed to in writing, software
|
||||||
|
# # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# # License for the specific language governing permissions and limitations
|
||||||
|
# # under the License.
|
||||||
|
|
||||||
|
|
||||||
|
- name: Load distro-specific variables
|
||||||
|
include_tasks: vars.yml
|
||||||
|
|
||||||
|
- name: Ensure chronyd is running
|
||||||
|
service:
|
||||||
|
enabled: "{{ (chrony_service_state|default('started') in ['running', 'started']) |bool }}"
|
||||||
|
name: "{{ chrony_service_name }}"
|
||||||
|
state: "{{ chrony_service_state|default('started') }}"
|
||||||
|
when: chrony_manage_service|bool
|
||||||
|
|
||||||
|
# ansible sometimes ignores handlers when invoked elsewhere. Since we will
|
||||||
|
# likely want to restart chrony after a configuration update, let's do it here
|
||||||
|
# always. The handler will still trigger for upgrades/updates later as well.
|
||||||
|
# This won't have any effect if chrony_manage_service is set to false.
|
||||||
|
# See also https://github.com/ansible/ansible/issues/37512
|
||||||
|
- name: Force chronyd restart
|
||||||
|
service:
|
||||||
|
name: "{{ chrony_service_name }}"
|
||||||
|
state: restarted
|
||||||
|
when:
|
||||||
|
- chrony_manage_service|bool
|
||||||
|
- chrony_config.changed|default(false)
|
22
tasks/sync.yml
Normal file
22
tasks/sync.yml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
---
|
||||||
|
# Copyright 2022 Red Hat, Inc.
|
||||||
|
# # All Rights Reserved.
|
||||||
|
# #
|
||||||
|
# # Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# # not use this file except in compliance with the License. You may obtain
|
||||||
|
# # a copy of the License at
|
||||||
|
# #
|
||||||
|
# # http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
# #
|
||||||
|
# # Unless required by applicable law or agreed to in writing, software
|
||||||
|
# # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# # License for the specific language governing permissions and limitations
|
||||||
|
# # under the License.
|
||||||
|
|
||||||
|
|
||||||
|
- name: Force NTP sync
|
||||||
|
command: chronyc makestep
|
||||||
|
|
||||||
|
- name: Ensure system is NTP time synced
|
||||||
|
command: chronyc waitsync 30
|
22
tasks/vars.yml
Normal file
22
tasks/vars.yml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
---
|
||||||
|
# Copyright 2022 Red Hat, Inc.
|
||||||
|
# # All Rights Reserved.
|
||||||
|
# #
|
||||||
|
# # Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# # not use this file except in compliance with the License. You may obtain
|
||||||
|
# # a copy of the License at
|
||||||
|
# #
|
||||||
|
# # http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
# #
|
||||||
|
# # Unless required by applicable law or agreed to in writing, software
|
||||||
|
# # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# # License for the specific language governing permissions and limitations
|
||||||
|
# # under the License.
|
||||||
|
|
||||||
|
- name: Load distro-specific variables
|
||||||
|
include_vars: "{{ item }}"
|
||||||
|
with_first_found:
|
||||||
|
- "{{ ansible_facts['distribution'] }}.yml"
|
||||||
|
- "{{ ansible_facts['os_family'] }}.yml"
|
||||||
|
- default.yml
|
Loading…
x
Reference in New Issue
Block a user