5 # Copyright:: 2022, OpenStreetMap Foundation
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # https://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
36 keys = data_bag_item("oxidized", "keys")
37 devices = data_bag_item("oxidized", "devices")
39 directory "/etc/oxidized" do
45 template "/etc/oxidized/config" do
50 notifies :restart, "service[oxidized]"
53 template "/etc/oxidized/routers.db" do
54 source "routers.db.erb"
58 variables :devices => devices
59 notifies :restart, "service[oxidized]"
62 directory "/var/log/oxidized" do
68 directory "/opt/oxidized" do
74 git "/opt/oxidized/daemon" do
76 repository "https://github.com/openstreetmap/oxidized.git"
80 notifies :run, "bundle_install[/opt/oxidized/daemon]", :immediately
83 directory "/opt/oxidized/.ssh" do
89 # Key is set as a deployment key in github repo
90 file "/opt/oxidized/.ssh/id_ed25519" do
91 content keys["git"].join("\n")
95 notifies :delete, "file[/opt/oxidized/.ssh/id_ed25519.pub]", :immediately
96 notifies :restart, "service[oxidized]"
99 # Ensure public key is deleted if private key is changed. Trigged by notify
100 file "/opt/oxidized/.ssh/id_ed25519.pub" do
104 execute "/opt/oxidized/.ssh/id_ed25519.pub" do
105 command "ssh-keygen -f /opt/oxidized/.ssh/id_ed25519 -y > /opt/oxidized/.ssh/id_ed25519.pub"
108 creates "/opt/oxidized/.ssh/id_ed25519.pub"
109 notifies :restart, "service[oxidized]"
112 ssh_known_hosts_entry "github.com" do
113 action [:create, :flush]
114 file_location "/opt/oxidized/.ssh/known_hosts"
119 directory "/var/lib/oxidized" do
125 git "/var/lib/oxidized/configs.git" do
127 repository "git@github.com:openstreetmap/oxidized-configs.git" # Uses oxidized ssh key
128 checkout_branch "master" # branch is hardcoded in oxidized
133 bundle_install "/opt/oxidized/daemon" do
135 options "--deployment"
138 notifies :restart, "service[oxidized]"
141 # Based on https://github.com/ytti/oxidized/blob/master/extra/oxidized.service
142 systemd_service "oxidized" do
143 description "oxidized network device backup daemon"
144 after "network.target"
146 working_directory "/opt/oxidized/daemon"
147 runtime_directory "oxidized"
148 exec_start "#{node[:ruby][:bundle]} exec oxidized"
149 environment "OXIDIZED_HOME" => "/etc/oxidized",
150 "OXIDIZED_LOGS" => "/var/log/oxidized"
152 sandbox :enable_network => true
153 read_write_paths ["/run/oxidized", "/var/lib/oxidized", "/var/log/oxidized"]
155 notifies :restart, "service[oxidized]"
158 service "oxidized" do
159 action [:enable, :start]
162 template "/etc/logrotate.d/oxidized" do
163 source "logrotate.erb"