Skip to content

Commit

Permalink
have a dedicated reflock attribute in chrony
Browse files Browse the repository at this point in the history
Summary: This is more of a cosmetic change to ensure we have all "sources" sections (servers/pools/refclocks) together

Differential Revision: D61383956

fbshipit-source-id: 191c011f15ec7d63ce5b97963aa250eee42c2a81
  • Loading branch information
leoleovich authored and facebook-github-bot committed Aug 16, 2024
1 parent 7a9b479 commit b672666
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
24 changes: 16 additions & 8 deletions cookbooks/fb_chrony/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ Attributes
* node['fb_chrony']['config']
* node['fb_chrony']['servers']
* node['fb_chrony']['pools']
* node['fb_chrony']['refclocks']
* node['fb_chrony']['default_options']
* node['fb_chrony']['leap']

Usage
-----
Include `fb_chrony::default` to manage Chrony. Servers and pools can be
configured via the `node['fb_chrony']['servers']` and
`node['fb_chrony']['pools']` attributes. These can be either lists or hashes;
in the first case, each item will have the same options, as defined in
`node['fb_chrony']['default_options']`. In the latter, items with empty values
will use `node['fb_chrony']['default_options']`, while the other will use the
value specified. For example:
Include `fb_chrony::default` to manage Chrony. Servers pools and refclocks can
be configured via the `node['fb_chrony']['servers']`,
`node['fb_chrony']['pools']` and `node['fb_chrony']['refclocks']` attributes.
These can be either lists or hashes;
in the first case, server and pool item will have the same options, as defined in
`node['fb_chrony']['default_options']`.
In the latter, server and pool with empty values will use
`node['fb_chrony']['default_options']`, while the other (including refclocks)
will use the value specified. For example:

```ruby
node['fb_chrony']['default_options'] = %w{iburst}
Expand All @@ -32,7 +35,10 @@ node.default['fb_chrony']['servers'] = {
node.default['fb_chrony']['pools'] = %w{
ntp1pool.example
ntp2pool.example
end
}
node.default['fb_chrony']['refclocks'] = %w{
"PHC /dev/ptp0": %w{poll 0}
}
```

will result in the following configuration:
Expand All @@ -43,6 +49,8 @@ server ntp2.example iburst
pool ntp1pool.example iburst
pool ntp2pool.example iburst
refclock PHC /dev/ptp0 poll 0
```

Other settings can be defined in `node['fb_chrony']['config']`.
1 change: 1 addition & 0 deletions cookbooks/fb_chrony/attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
'manage_packages' => true,
'servers' => server_list,
'pools' => {},
'refclocks' => {},
# https://chrony.tuxfamily.org/doc/3.4/chrony.conf.html
'default_options' => %w{iburst},
'config' => {
Expand Down
14 changes: 13 additions & 1 deletion cookbooks/fb_chrony/templates/default/chrony.conf.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is maintained by Chef. Do not edit, all changes will be
# overwritten. See opsfiles/chef/cookbooks/core/fb_chrony

<%
<%
default_opts = node['fb_chrony']['default_options'].join(' ')

if node['fb_chrony']['servers'].is_a?(Array)
Expand All @@ -21,13 +21,25 @@
else
pools = node['fb_chrony']['pools'].to_hash
end

if node['fb_chrony']['refclocks'].is_a?(Array)
refclocks = {}
node['fb_chrony']['refclocks'].each do |refclock|
refclocks[refclock] = []
end
else
refclocks = node['fb_chrony']['refclocks'].to_hash
end
%>
<% servers.each do |server, opts| -%>
server <%= server %> <%= opts && !opts.empty? ? opts.join(' ') : default_opts %>
<% end -%>
<% pools.each do |pool, opts| -%>
pool <%= pool %> <%= opts && !opts.empty? ? opts.join(' ') : default_opts %>
<% end -%>
<% refclocks.each do |refclock, opts| -%>
refclock <%= refclock %> <%= opts.join(' ')%>
<% end -%>
<% node['fb_chrony']['config'].to_hash.each do |key, val| %>
<%= key %> <%= val %>
Expand Down

0 comments on commit b672666

Please sign in to comment.