diff --git a/lvm-snapshots/defaults/main.yml b/lvm-snapshots/defaults/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..be23d6f080821cd74e4741f244d5613fe720e33d --- /dev/null +++ b/lvm-snapshots/defaults/main.yml @@ -0,0 +1,18 @@ +--- +# file: roles/lvm-snapshots/defaults/main.yml + +program_dir: /opt/lvm-snapshots +snapshot_cron_minutes: 15 +snapshot_volumes: + - volume_group: exports + name: pub + path: .snapshots + keep: + - number: 4 + interval: 15M + - number: 24 + interval: 1H + - number: 31 + interval: 1d + - number: 6 + interval: 1m diff --git a/lvm-snapshots/files/ssh-config.lvm-snapshots b/lvm-snapshots/files/ssh-config.lvm-snapshots new file mode 100644 index 0000000000000000000000000000000000000000..882666b6f5b50ebac92e6ecf252ea7e08bd0b0c2 --- /dev/null +++ b/lvm-snapshots/files/ssh-config.lvm-snapshots @@ -0,0 +1,4 @@ +Host git.fsmpi.rwth-aachen.de +HostName git.fsmpi.rwth-aachen.de +User git +IdentityFile lvm-snapshots.key diff --git a/lvm-snapshots/tasks/main.yml b/lvm-snapshots/tasks/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..b2789499fe6bde2ccd8ab87b2010b484219ec07e --- /dev/null +++ b/lvm-snapshots/tasks/main.yml @@ -0,0 +1,131 @@ +--- +# file: roles/lvm-snapshots/tasks/main.yml + +- name: ensure we have the target folder + file: path="{{program_dir}}" state=directory owner=root group=root mode=0755 + tags: + - lvm-snapshots + - directory + +- name: ensure we know our deploy key + local_action: pass name="deploy-key/lvm-snapshots" state=present store=FSMPI_PASSWORD_STORE_DIR limit=no + register: deploy_key + no_log: True + tags: + - lvm-snapshots + - password + +- name: ensure we know our public deploy key + local_action: pass name="deploy-key/lvm-snapshots-public" state=present store=FSMPI_PASSWORD_STORE_DIR limit=no + register: deploy_key_public + no_log: True + tags: + - lvm-snapshots + - password + +- name: ensure our deploy key is present + copy: + content: "{{deploy_key.password}}\n" + dest: /root/.ssh/lvm-snapshots.key + owner: root + group: root + mode: 0600 + no_log: True + tags: + - lvm-snapshots + - ssh + +- name: ensure our public deploy key is present + copy: + content: "{{deploy_key_public.password}}\n" + dest: /root/.ssh/lvm-snapshots.pub + owner: root + group: root + mode: 0644 + no_log: True + tags: + - lvm-snapshots + - ssh + +- name: ensure we have our lvm-snapshots ssh config + copy: + src: ssh-config.lvm-snapshots + dest: /root/.ssh/config.lvm-snapshots + owner: root + group: root + mode: 0644 + tags: + - lvm-snapshots + - ssh + - config + +- name: ensure our lvm-snapshots ssh config is included + lineinfile: + dest: /root/.ssh/config + line: "Include config.lvm-snapshots" + create: yes + owner: root + group: root + mode: 0644 + tags: + - lvm-snapshots + - ssh + - config + +- name: ensure we have the program + git: + repo: git@git.fsmpi.rwth-aachen.de:infra/lvm-snapshots.git + dest: "{{program_dir}}" + tags: + - git + - lvm-snapshots + +- name: ensure the necessary programs are installed + apt: name="{{item}}" state=present + with_items: + - python3 + - virtualenv + tags: + - packages + - lvm-snapshots + +- name: ensure we have a virtualenv + pip: + requirements: "{{program_dir}}/requirements.txt" + virtualenv: "{{program_dir}}" + virtualenv_python: python3 + tags: + - pip + - python + - lvm-snapshots + +- name: ensure we have a frontend script + template: + src: script.sh + dest: /usr/local/sbin/lvm-snapshots + owner: root + group: root + mode: 0755 + tags: + - lvm-snapshots + - config + +- name: ensure we have our config + template: + src: config.toml + dest: /etc/lvm-snapshots.toml + owner: root + group: root + mode: 0644 + tags: + - lvm-snapshots + - config + +- name: ensure we have a cron job + cron: + name: "lvm-snapshots" + minute: "*/{{snapshot_cron_minutes}}" + job: "/usr/local/sbin/lvm-snapshots update" + tags: + - lvm-snapshots + - cron diff --git a/lvm-snapshots/templates/config.toml b/lvm-snapshots/templates/config.toml new file mode 100644 index 0000000000000000000000000000000000000000..7ff4d5f096c43ea8f88a8fba7a6f05f321fc280a --- /dev/null +++ b/lvm-snapshots/templates/config.toml @@ -0,0 +1,13 @@ +{% for volume in snapshot_volumes %} +[[volume]] + volume_group = "{{volume.volume_group}}" + name = "{{volume.name}}" + path = "{{volume.path}}" + {% for keep in volume.keep %} + + [[volume.keep]] + number = {{keep.number}} + interval = "{{keep.interval}}" + {% endfor %} + +{% endfor %} diff --git a/lvm-snapshots/templates/script.sh b/lvm-snapshots/templates/script.sh new file mode 100644 index 0000000000000000000000000000000000000000..33dabb71f4c880b44c348c978af2c4534e4e7acb --- /dev/null +++ b/lvm-snapshots/templates/script.sh @@ -0,0 +1,3 @@ +#!/bin/bash +{{program_dir}}/bin/python {{program_dir}}/lvmsnapshot.py "$@" +exit $?