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.
35 keys = data_bag_item("oxidized", "keys")
36 devices = data_bag_item("oxidized", "devices")
38 directory "/etc/oxidized" do
44 template "/etc/oxidized/config" do
49 notifies :restart, "service[oxidized]"
52 template "/etc/oxidized/routers.db" do
53 source "routers.db.erb"
57 variables :devices => devices
58 notifies :restart, "service[oxidized]"
61 directory "/var/log/oxidized" do
67 directory "/opt/oxidized" do
73 git "/opt/oxidized/daemon" do
75 repository "https://github.com/openstreetmap/oxidized.git"
79 notifies :run, "bundle_install[/opt/oxidized/daemon]", :immediately
82 directory "/opt/oxidized/.ssh" do
88 # Key is set as a deployment key in github repo
89 file "/opt/oxidized/.ssh/id_ed25519" do
90 content keys["git"].join("\n")
94 notifies :delete, "file[/opt/oxidized/.ssh/id_ed25519.pub]", :immediately
95 notifies :restart, "service[oxidized]"
98 # Ensure public key is deleted if private key is changed. Trigged by notify
99 file "/opt/oxidized/.ssh/id_ed25519.pub" do
103 execute "/opt/oxidized/.ssh/id_ed25519.pub" do
104 command "ssh-keygen -f /opt/oxidized/.ssh/id_ed25519 -y > /opt/oxidized/.ssh/id_ed25519.pub"
107 creates "/opt/oxidized/.ssh/id_ed25519.pub"
108 notifies :restart, "service[oxidized]"
111 ssh_known_hosts_entry "github.com" do
112 action [:create, :flush]
113 file_location "/opt/oxidized/.ssh/known_hosts"
118 directory "/var/lib/oxidized" do
124 git "/var/lib/oxidized/configs.git" do
126 repository "git@github.com:openstreetmap/oxidized-configs.git" # Uses oxidized ssh key
127 checkout_branch "master" # branch is hardcoded in oxidized
132 bundle_install "/opt/oxidized/daemon" do
134 options "--deployment"
137 notifies :restart, "service[oxidized]"
140 # Based on https://github.com/ytti/oxidized/blob/master/extra/oxidized.service
141 systemd_service "oxidized" do
142 description "oxidized network device backup daemon"
143 after "network.target"
145 working_directory "/opt/oxidized/daemon"
146 runtime_directory "oxidized"
147 exec_start "#{node[:ruby][:bundle]} exec oxidized"
148 environment "OXIDIZED_HOME" => "/etc/oxidized",
149 "OXIDIZED_LOGS" => "/var/log/oxidized"
151 sandbox :enable_network => true
152 read_write_paths ["/run/oxidized", "/var/lib/oxidized", "/var/log/oxidized"]
154 notifies :restart, "service[oxidized]"
157 service "oxidized" do
158 action [:enable, :start]
161 template "/etc/logrotate.d/oxidized" do
162 source "logrotate.erb"