Skip to content

Commit 8e61a06

Browse files
author
tedezed
committed
Cron backups
1 parent 3b3b0c1 commit 8e61a06

26 files changed

+227
-69
lines changed

Diff for: .gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
vagrant_ansible_inventory
55
inventory-blk
66
.create_hosts.sh
7-
tools/build_variable_domain
7+
tools/build_variable_domain
8+
.custom_cache

Diff for: Makefile

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
1-
SHELL := /bin/bash
1+
SHELL:=/bin/bash
2+
INVENTORY_DIR:=inventory
3+
#INVENTORY_DIR:=inventory-blk
24

3-
up:
5+
vagrant_up:
46
#export VAGRANTFILE_API_VERSION="2"
57
#export VAGRANT_DISABLE_VBOXSYMLINKCREATE=1
68
vboxmanage list vms
79
vagrant up
810

9-
destroy:
11+
vagrant_destroy:
1012
rm -rf ~/.ssh/known_hosts
11-
rm -rf .vagrant/provisioners/ansible/inventory && vagrant destroy -f
13+
rm -rf .vagrant/provisioners/ansible/${INVENTORY_DIR} && vagrant destroy -f
1214
rm -rf .vagrant/
1315
rm -rf ubuntu-*
1416

1517
domain:
1618
source tools/generated_domain.sh
1719

18-
ansible: domain
19-
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i inventory/local/hosts.ini --become --become-user=root ansible.yml --extra-vars "$(shell cat tools/build_variable_domain)" -vvv --limit all
20+
install: domain
21+
sed -i 's/_setup: false/_setup: true/' ${INVENTORY_DIR}/local/group_vars/all/all.yml
22+
sed -i 's/_uninstall: true/_uninstall: false/' ${INVENTORY_DIR}/local/group_vars/all/all.yml
23+
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i ${INVENTORY_DIR}/local/hosts.ini --become --become-user=root ansible.yml --extra-vars "$(shell cat tools/build_variable_domain)" -v --limit all
2024

21-
deploy: up ansible
25+
uninstall: domain
26+
sed -i 's/_setup: true/_setup: false/' ${INVENTORY_DIR}/local/group_vars/all/all.yml
27+
sed -i 's/_uninstall: false/_uninstall: true/' ${INVENTORY_DIR}/local/group_vars/all/all.yml
28+
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i ${INVENTORY_DIR}/local/hosts.ini --become --become-user=root ansible.yml --extra-vars "$(shell cat tools/build_variable_domain)" -v --limit all
2229

23-
upgrade_vagrant:
24-
rm -rf .vagrant/provisioners/ansible/inventory
30+
vagrant_deploy: vagrant_up install
31+
32+
vagrant_upgrade:
33+
rm -rf .vagrant/provisioners/ansible/${INVENTORY_DIR}
2534
./tools/upgrade_vagrant.bash
2635
rm -rf *.deb && rm -rf *.deb\.*

Diff for: inventory/local/group_vars/all/all.yml

+10-16
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
---
2-
main_setup: true
3-
bind9_setup: true
4-
ldap_setup: true
5-
kerberos_setup: true
6-
sssd_setup: true
2+
main_setup: false
3+
bind9_setup: false
4+
ldap_setup: false
5+
kerberos_setup: false
6+
sssd_setup: false
77

8-
main_uninstall: false
9-
bind9_uninstall: false
10-
ldap_uninstall: false
11-
kerberos_uninstall: false
12-
sssd_uninstall: false
8+
main_uninstall: true
9+
bind9_uninstall: true
10+
ldap_uninstall: true
11+
kerberos_uninstall: true
12+
sssd_uninstall: true
1313

1414
domain: '{{ domainbase }}'
1515
openldap_org: '{{ organization }}'
1616
openldap_base: '{{ openldap_base }}'
1717
sudoers: "SUDOers"
1818

19-
# In virtualbox: 0 is internal, 1 private and 2 public IP
20-
# For more information see the Vagrantfile
21-
#num_interface: 1
22-
23-
# In normal machine: 0 == eth0
24-
num_interface: 0

Diff for: roles/bind9/files/bind_backup

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
DAYS_DELETE="10"
4+
DATE_NOW=$(date +%d-%m-%Y)
5+
BACKUP_PATH=/mnt/backups/bind
6+
7+
mkdir -p ${BACKUP_PATH}
8+
cd ${BACKUP_PATH}
9+
10+
tar -czf bind_etc_${DATE_NOW}.tar.gz /etc/bind
11+
12+
find ${BACKUP_PATH} -mtime +$DAYS_DELETE -iname "*.tar.gz" -exec rm -f {} \;

Diff for: roles/bind9/files/logrotate_bind_backup

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/var/logs/bind_backup.log {
2+
rotate 3
3+
monthly
4+
compress
5+
missingok
6+
notifempty
7+
}

Diff for: roles/bind9/tasks/install_bind9.yml

+18
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,21 @@
3939
name: bind9
4040
state: restarted
4141
enabled: yes
42+
43+
- name: Copy script backup and logrotate
44+
copy:
45+
src: "{{ item.src }}"
46+
dest: "{{ item.dest }}"
47+
mode: "{{ item.mode }}"
48+
with_items:
49+
- { src: "{{ role_path }}/files/bind_backup", dest: "/usr/local/bin/bind_backup", mode: "0755" }
50+
- { src: "{{ role_path }}/files/logrotate_bind_backup", dest: "/etc/logrotate.d/logrotate_bind_backup", mode: "0655" }
51+
52+
- name: Configure cron for bind_backup
53+
cron:
54+
name: "ansible_bind_backup"
55+
user: root
56+
cron_file: "ansible_bind_backup"
57+
minute: "0"
58+
hour: "1"
59+
job: "/usr/local/bin/bind_backup >> /var/logs/bind_backup.log"

Diff for: roles/bind9/tasks/uninstall_bind9.yml

+12-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@
77
state: absent
88
update_cache: yes
99

10-
- name: Recursively remove directory
10+
- name: Remove extra dirs and files
1111
file:
12-
path: /etc/bind
13-
state: absent
12+
path: "{{ item }}"
13+
state: absent
14+
with_items:
15+
- /etc/bind
16+
- /etc/logrotate.d/logrotate_bind_backup
17+
18+
- name : Delete cron for bind_backup
19+
cron :
20+
name : ansible_bind_backup
21+
cron_file: ansible_bind_backup
22+
state : absent

Diff for: roles/bind9/templates/db.template.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $TTL 604800
1818
{% if (group !='bind9') %}
1919
{{ group }} IN CNAME {{ groups[group][0] }}
2020
{% else %}
21-
{{ group }} IN A {{ hostvars[groups['bind9'][0]].ansible_all_ipv4_addresses[num_interface] }}
21+
{{ group }} IN A {{ hostvars[groups['bind9'][0]].ansible_host }}
2222
{% endif %}
2323
{% endif %}
2424
{% endfor %}

Diff for: roles/bind9/templates/hosts.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
127.0.0.1 localhost bind9 {{ groups['bind9'][0] }}
2-
{{ hostvars[groups['bind9'][0]].ansible_all_ipv4_addresses[num_interface] }} bind9.{{ domain }} bind9
2+
{{ hostvars[groups['bind9'][0]].ansible_host }} bind9.{{ domain }} bind9

Diff for: roles/bind9/templates/named.conf.options.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ options {
22
directory "/var/cache/bind";
33
auth-nxdomain no; # conform to RFC1035
44
// listen-on-v6 { any; };
5-
listen-on port 53 { localhost; {{ hostvars[groups['bind9'][0]].ansible_all_ipv4_addresses[num_interface] }}; };
5+
listen-on port 53 { localhost; {{ hostvars[groups['bind9'][0]].ansible_host }}; };
66
allow-query { localhost; any; };
77
forwarders { 8.8.8.8; };
88
recursion yes;

Diff for: roles/bind9/templates/resolv.conf.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
domain {{ domain }}
22
search bind9.{{ domain }}
3-
nameserver {{ hostvars[groups['bind9'][0]].ansible_all_ipv4_addresses[num_interface] }}
3+
nameserver {{ hostvars[groups['bind9'][0]].ansible_host }}
44

Diff for: roles/common/tasks/main_install.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
- name: Interface IP
33
debug:
44
msg:
5-
- "Interface IP: {{ hostvars[groups['bind9'][0]].ansible_all_ipv4_addresses[num_interface] }}"
5+
- "Interface IP: {{ hostvars[groups['bind9'][0]].ansible_host }}"
66

77
- name: Create /etc/resolv.conf
88
template:

Diff for: roles/common/templates/resolv.conf.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
domain {{ domain }}
22
search bind9.{{ domain }}
3-
nameserver {{ hostvars[groups['bind9'][0]].ansible_all_ipv4_addresses[num_interface] }}
3+
nameserver {{ hostvars[groups['bind9'][0]].ansible_host }}
44

Diff for: roles/kerberos/defaults/main.yml

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ kdc_port: 88
55
kdc_conf_path: /etc/krb5kdc/kdc.conf
66
kadm5_acl_path: /etc/krb5kdc/kadm5.acl
77

8+
ticket_lifetime: 72h
9+
renew_lifetime: 120d
10+
811
# Passwd policy
912
maxlife: "3 months"
1013
minlife: "1 months"

Diff for: roles/kerberos/files/kerberos_backup

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
DAYS_DELETE="10"
4+
DATE_NOW=$(date +%d-%m-%Y)
5+
BACKUP_PATH=/mnt/backups/kerberos
6+
7+
mkdir -p ${BACKUP_PATH}
8+
cd ${BACKUP_PATH}
9+
10+
/usr/sbin/kdb5_util dump kdb5_${DATE_NOW}.dump
11+
12+
cp /etc/krb5.conf /etc/krb5_${DATE_NOW}.conf
13+
cp /etc/krb5.keytab /etc/krb5_${DATE_NOW}.conf
14+
15+
tar -czf krb5kdc_etc_${DATE_NOW}.tar.gz /etc/krb5kdc
16+
tar -czf krb5kdc_var_${DATE_NOW}.tar.gz /var/lib/krb5kdc
17+
18+
find ${BACKUP_PATH} -mtime +$DAYS_DELETE -iname "*.dump" -exec rm -f {} \;
19+
find ${BACKUP_PATH} -mtime +$DAYS_DELETE -iname "*.conf" -exec rm -f {} \;
20+
find ${BACKUP_PATH} -mtime +$DAYS_DELETE -iname "*.tar.gz" -exec rm -f {} \;

Diff for: roles/kerberos/files/logrotate_kerberos_backup

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/var/logs/kerberos_backup.log {
2+
rotate 3
3+
monthly
4+
compress
5+
missingok
6+
notifempty
7+
}

Diff for: roles/kerberos/tasks/install_kerberos.yml

+18-5
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,21 @@
5353
- name: Create default password policy
5454
shell: kadmin.local -q "add_policy -maxlife \"{{ maxlife }}\" -minlife \"{{ minlife }}\" -minlength {{ minlength }} -minclasses {{ minclasses }} -history {{ history }} -maxfailure {{ maxfailure }} -failurecountinterval \"{{ failurecountinterval }}\" -lockoutduration \"{{ lockoutduration }}\" {{ policy_name }}"
5555

56-
- name: Copy blksmanager
57-
copy:
58-
src: "{{ role_path }}/files/blksmanager"
59-
dest: /usr/local/bin/blksmanager
60-
mode: 0755
56+
- name: Copy blksmanager, script backup and logrotate
57+
copy:
58+
src: "{{ item.src }}"
59+
dest: "{{ item.dest }}"
60+
mode: "{{ item.mode }}"
61+
with_items:
62+
- { src: "{{ role_path }}/files/blksmanager", dest: "/usr/local/bin/blksmanager", mode: "0755" }
63+
- { src: "{{ role_path }}/files/kerberos_backup", dest: "/usr/local/bin/kerberos_backup", mode: "0755" }
64+
- { src: "{{ role_path }}/files/logrotate_kerberos_backup", dest: "/etc/logrotate.d/logrotate_kerberos_backup", mode: "0655" }
65+
66+
- name: Configure cron for kerberos_backup
67+
cron:
68+
name: ansible_kerberos_backup
69+
user: root
70+
cron_file: ansible_kerberos_backup
71+
minute: "0"
72+
hour: "2"
73+
job: "/usr/local/bin/kerberos_backup >> /var/logs/kerberos_backup.log"

Diff for: roles/kerberos/tasks/uninstall_kerberos.yml

+11-7
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@
1515
- ldap-utils
1616
- krb5-user
1717

18-
19-
- name: Recursively remove directory
18+
- name: Remove extra dirs and files
2019
file:
21-
path: /etc/krb5kdc
20+
path: "{{ item }}"
2221
state: absent
22+
with_items:
23+
- /etc/krb5kdc
24+
- /usr/local/bin/blksmanager
25+
- /etc/logrotate.d/logrotate_kerberos_backup
2326

24-
- name: Remove blksmanager
25-
file:
26-
path: /usr/local/bin/blksmanager
27-
state: absent
27+
- name : Delete cron for kerberos_backup
28+
cron :
29+
name : ansible_kerberos_backup
30+
cron_file: ansible_kerberos_backup
31+
state : absent

Diff for: roles/kerberos/templates/krb5.conf.j2

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
default_realm = {{ realm_name|upper() }}
88
dns_lookup_realm = false
99
dns_lookup_kdc = false
10-
ticket_lifetime = 24h
11-
renew_lifetime = 7d
10+
ticket_lifetime = {{ ticket_lifetime }}
11+
renew_lifetime = {{ renew_lifetime }}
1212
forwardable = true
1313

1414
[realms]

Diff for: roles/ldap/files/ldap_backup

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
DAYS_DELETE="10"
4+
DATE_NOW=$(date +%d-%m-%Y)
5+
BACKUP_PATH=/mnt/backups/ldap
6+
7+
mkdir -p ${BACKUP_PATH}
8+
cd ${BACKUP_PATH}
9+
10+
/usr/sbin/slapcat -n 0 > config_${DATE_NOW}.ldif
11+
/usr/sbin/slapcat -n 1 > domain_${DATE_NOW}.ldif
12+
13+
tar -czf ldap_etc_${DATE_NOW}.tar.gz /etc/ldap
14+
tar -czf ldap_var_${DATE_NOW}.tar.gz /var/lib/ldap
15+
16+
find ${BACKUP_PATH} -mtime +$DAYS_DELETE -iname "*.ldif" -exec rm -f {} \;
17+
find ${BACKUP_PATH} -mtime +$DAYS_DELETE -iname "*.tar.gz" -exec rm -f {} \;

Diff for: roles/ldap/files/logrotate_ldap_backup

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/var/logs/ldap_backup.log {
2+
rotate 3
3+
monthly
4+
compress
5+
missingok
6+
notifempty
7+
}

Diff for: roles/ldap/tasks/config_openldap.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
with_items:
8686
- slapdconf add-module memberof
8787
- slapdconf add-overlay {{ openldap_base }} memberof
88-
when: active_memberof|failed
88+
when: active_memberof.failed
8989

9090
- name: Check install module ldap refint
9191
shell: slapdconf list-modules | grep 'refint'
@@ -97,4 +97,4 @@
9797
with_items:
9898
- slapdconf add-module refint
9999
- slapdconf add-overlay {{ openldap_base }} refint olcRefintConfig 'olcRefintAttribute:memberof member manager owner'
100-
when: active_refint|failed
100+
when: active_refint.failed

Diff for: roles/ldap/tasks/install_openldap.yml

+23-4
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,38 @@
3737
tags:
3838
- install_packages_ldap
3939

40-
- debug:
40+
- name: Debug install_ldap_packages
41+
debug:
4142
msg: '{{install_ldap_packages}}'
4243

4344
- name: Validating correct install
4445
apt:
4546
name: "{{ openldap_packages }}"
46-
update_cache: yes
47+
update_cache: "yes"
4748
state: present
4849
environment:
4950
SUDO_FORCE_REMOVE: "yes"
50-
when: install_ldap_packages|failed
51+
when: install_ldap_packages.failed
5152
tags:
5253
- repairs_packages_ldap
5354

5455
- include: config_openldap.yml
55-
- include: read_only_openldap.yml
56+
- include: read_only_openldap.yml
57+
58+
- name: Copy script backup and logrotate
59+
copy:
60+
src: "{{ item.src }}"
61+
dest: "{{ item.dest }}"
62+
mode: "{{ item.mode }}"
63+
with_items:
64+
- { src: "{{ role_path }}/files/ldap_backup", dest: "/usr/local/bin/ldap_backup", mode: "0755" }
65+
- { src: "{{ role_path }}/files/logrotate_ldap_backup", dest: "/etc/logrotate.d/logrotate_ldap_backup", mode: "0655" }
66+
67+
- name: Configure cron for ldap_backup
68+
cron:
69+
name: ansible_ldap_backup
70+
user: root
71+
cron_file: ansible_ldap_backup
72+
minute: "30"
73+
hour: "1"
74+
job: "/usr/local/bin/ldap_backup >> /var/logs/ldap_backup.log"

0 commit comments

Comments
 (0)