Move borg credentials to a separate file

To be used from a service
This commit is contained in:
Râu Cao 2022-10-21 10:49:02 +02:00
parent 374654f8fd
commit a5b2eb5f97

View File

@ -12,16 +12,24 @@ file "/root/.ssh/borg_rsa" do
mode '0600' mode '0600'
end end
bash "Add borg environment variables for bash" do file "/root/.borg_credentials.env" do
content <<-EOF
BORG_RSH='ssh -i /root/.ssh/borg_rsa'
BORG_PASSPHRASE=#{borg_credentials["passphrase"]}
BORG_REPO='#{borg_credentials["repository"]}'
EOF
end
bash "Load borg credentials in console sessions" do
code <<-EOF code <<-EOF
cat >>/root/.bashrc <<EOL cat >>/root/.bashrc <<EOL
# GENERATED BY CHEF # GENERATED BY CHEF
export BORG_RSH='ssh -i /root/.ssh/borg_rsa' set -o allexport
export BORG_PASSPHRASE=#{borg_credentials["passphrase"]} source ~/.borg_credentials.env
export BORG_REPO='#{borg_credentials["repository"]}' set +o allexport
EOF EOF
not_if "grep -q BORG /root/.bashrc" not_if "grep -q borg_credentials /root/.bashrc"
end end
directory "/root/backups" do directory "/root/backups" do