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
1 changed files with 13 additions and 5 deletions

View File

@ -12,16 +12,24 @@ file "/root/.ssh/borg_rsa" do
mode '0600'
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
cat >>/root/.bashrc <<EOL
# GENERATED BY CHEF
export BORG_RSH='ssh -i /root/.ssh/borg_rsa'
export BORG_PASSPHRASE=#{borg_credentials["passphrase"]}
export BORG_REPO='#{borg_credentials["repository"]}'
set -o allexport
source ~/.borg_credentials.env
set +o allexport
EOF
not_if "grep -q BORG /root/.bashrc"
not_if "grep -q borg_credentials /root/.bashrc"
end
directory "/root/backups" do