Skip to content

Commit

Permalink
Make the behavior of chronyd_sync_clock rule more consistent
Browse files Browse the repository at this point in the history
Previous template lineinfile usage will append the configuration even when there is an existing line. Use key_value_pair_in_file to make sure its behavior.
  • Loading branch information
alanmcanonical committed May 31, 2024
1 parent 0d542f3 commit fd8c3e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions linux_os/guide/services/ntp/chronyd_sync_clock/rule.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
documentation_complete: true

{{% if product == 'ubuntu2204' -%}}
{{% set makestep_line = 'makestep 1 1' -%}}
{{% set step_value = '1 1' -%}}
{{% else -%}}
{{% set makestep_line = 'makestep 1 -1' -%}}
{{% set step_value = '1 -1' -%}}
{{% endif -%}}

title: 'Synchronize internal information system clocks'
Expand Down Expand Up @@ -34,16 +34,19 @@ ocil: |-
authoritative time source when the time difference is greater than one
second. Check the value of "makestep" by running the following command:
<pre>$ sudo grep makestep {{{ chrony_conf_path }}}
{{{ makestep_line }}}</pre>
makestep {{{ step_value }}}</pre>
If it is not set to the above value, edit the {{{ chrony_conf_path }}} file
and add:
<pre>{{{ makestep_line }}}</pre>
<pre>makestep {{{ step_value }}}</pre>
Restart the chrony service:
<pre>$ sudo systemctl restart chrony.service</pre>
template:
name: "lineinfile"
name: key_value_pair_in_file
vars:
text: {{{ makestep_line }}}
key: "makestep"
value: {{{ step_value }}}
sep: ' '
sep_regex: ' '
path: {{{ chrony_conf_path }}}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# packages = chrony

{{% if product == 'ubuntu2204' -%}}
echo "makestep 1 1" >> {{{ chrony_conf_path }}}
echo "makestep 1 1" > {{{ chrony_conf_path }}}
{{% else -%}}
echo "makestep 1 -1" >> {{{ chrony_conf_path }}}
echo "makestep 1 -1" > {{{ chrony_conf_path }}}
{{% endif -%}}

0 comments on commit fd8c3e9

Please sign in to comment.