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.
34 keys = data_bag_item("oxidized", "keys")
35 devices = data_bag_item("oxidized", "devices")
37 directory "/etc/oxidized" do
43 template "/etc/oxidized/config" do
48 notifies :restart, "service[oxidized]"
51 template "/etc/oxidized/routers.db" do
52 source "routers.db.erb"
56 variables :devices => devices
57 notifies :restart, "service[oxidized]"
60 directory "/var/log/oxidized" do
66 directory "/opt/oxidized" do
72 git "/opt/oxidized/daemon" do
74 repository "https://github.com/openstreetmap/oxidized.git"
78 notifies :run, "bundle_install[/opt/oxidized/daemon]", :immediately
81 directory "/opt/oxidized/.ssh" do
87 # Key is set as a deployment key in github repo
88 file "/opt/oxidized/.ssh/id_ed25519" do
89 content keys["git"].join("\n")
93 notifies :delete, "file[/opt/oxidized/.ssh/id_ed25519.pub]", :immediately
94 notifies :restart, "service[oxidized]"
97 # Ensure public key is deleted if private key is changed. Trigged by notify
98 file "/opt/oxidized/.ssh/id_ed25519.pub" do
102 execute "/opt/oxidized/.ssh/id_ed25519.pub" do
103 command "ssh-keygen -f /opt/oxidized/.ssh/id_ed25519 -y > /opt/oxidized/.ssh/id_ed25519.pub"
106 creates "/opt/oxidized/.ssh/id_ed25519.pub"
107 notifies :restart, "service[oxidized]"
110 ssh_known_hosts_entry "github.com" do
111 action [:create, :flush]
112 file_location "/opt/oxidized/.ssh/known_hosts"
117 directory "/var/lib/oxidized" do
123 git "/var/lib/oxidized/configs.git" do
125 repository "git@github.com:openstreetmap/oxidized-configs.git" # Uses oxidized ssh key
126 checkout_branch "master" # branch is hardcoded in oxidized
131 bundle_install "/opt/oxidized/daemon" do
133 options "--deployment"
136 notifies :restart, "service[oxidized]"
139 # Based on https://github.com/ytti/oxidized/blob/master/extra/oxidized.service
140 systemd_service "oxidized" do
141 description "oxidized network device backup daemon"
142 after "network.target"
144 working_directory "/opt/oxidized/daemon"
145 runtime_directory "oxidized"
146 exec_start "#{node[:ruby][:bundle]} exec oxidized"
147 environment "OXIDIZED_HOME" => "/etc/oxidized",
148 "OXIDIZED_LOGS" => "/var/log/oxidized"
150 sandbox :enable_network => true
151 read_write_paths ["/run/oxidized", "/var/lib/oxidized", "/var/log/oxidized"]
153 notifies :restart, "service[oxidized]"
156 service "oxidized" do
157 action [:enable, :start]
160 template "/etc/logrotate.d/oxidized" do
161 source "logrotate.erb"