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_config "/opt/oxidized/daemon" do
 
 136   settings "deployment" => "true",
 
 137            "build.rugged" => "--with-ssh"
 
 140 bundle_install "/opt/oxidized/daemon" do
 
 144   notifies :restart, "service[oxidized]"
 
 147 # Based on https://github.com/ytti/oxidized/blob/master/extra/oxidized.service
 
 148 systemd_service "oxidized" do
 
 149   description "oxidized network device backup daemon"
 
 150   after "network.target"
 
 152   working_directory "/opt/oxidized/daemon"
 
 153   runtime_directory "oxidized"
 
 154   exec_start "#{node[:ruby][:bundle]} exec oxidized"
 
 155   environment "OXIDIZED_HOME" => "/etc/oxidized",
 
 156               "OXIDIZED_LOGS" => "/var/log/oxidized"
 
 158   sandbox :enable_network => true
 
 159   restrict_address_families "AF_NETLINK"
 
 160   read_write_paths ["/run/oxidized", "/var/lib/oxidized", "/var/log/oxidized"]
 
 162   notifies :restart, "service[oxidized]"
 
 165 service "oxidized" do
 
 166   action [:enable, :start]
 
 169 template "/etc/logrotate.d/oxidized" do
 
 170   source "logrotate.erb"