-
Notifications
You must be signed in to change notification settings - Fork 1
/
linux.rb
88 lines (79 loc) · 2.11 KB
/
linux.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#
# Cookbook Name:: aws-ec2-snapshot
# Recipe:: linux
#
# Install wget
package 'wget' do
action :install
end
# Creat the backerupper user
user 'backerupper' do
supports :manage_home => true
comment 'User for EC2 snapshots'
uid 5555
home '/home/backerupper'
shell '/bin/bash'
end
# Configure the AWS CLI tools with the backerupper AWS credentials (if not using an IAM instance role), may not have to do this
# if it's already taken care of in the awscli-cookbook installation
# Drop in the bash script
directory '/opt/aws' do
owner 'backerupper'
group 'backerupper'
mode '755'
action :create
end
template '/opt/aws/ebs-snapshot.sh' do
source 'ebs-snapshot.erb'
owner 'backerupper'
mode '755'
variables(
:snapshot_retention => node['aws-ec2-snapshot']['days_to_keep_snapshot']
)
end
# Create a crontab entry for the backerupper user
cookbook_file '/var/spool/cron/backerupper' do
source 'backerupper'
owner 'backerupper'
group 'backerupper'
mode '600'
action :create
end
# If the system isn't configured to use an IAM role we need to copy in the
# configuration for the AWS CLI in order for things to work properly.
if node['aws-ec2-snapshot']['instance_uses_iam_role'] == false
# Create the directory for the aws config
directory '/home/backerupper/.aws' do
owner 'backerupper'
group 'backerupper'
mode '770'
action :create
end
# Create the credentials file
template '/home/backerupper/.aws/credentials' do
source 'credentials.erb'
owner 'backerupper'
group 'backerupper'
mode '770'
variables(
:aws_access_key_id => node['aws-ec2-snapshot']['aws_access_key_id'],
:aws_secret_access_key => node['aws-ec2-snapshot']['aws_secret_access_key']
)
end
# Create the config file
template '/home/backerupper/.aws/config' do
source 'config.erb'
owner 'backerupper'
group 'backerupper'
mode '770'
variables(
:region => node['aws-ec2-snapshot']['region']
)
end
end
# Touch the log file and give it permissions if it doesn't exist
file '/var/log/ebs-snapshot.log' do
owner 'backerupper'
mode '775'
action :create
end