Skip to content

Commit

Permalink
Update Ubuntu for testing + fix molecule lint issues (#7)
Browse files Browse the repository at this point in the history
* Update Ubuntu for testing + fix molecule lint issues

* Improve loops
  • Loading branch information
boutetnico authored Aug 23, 2022
1 parent 7e8b51a commit b7746b3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ This role configures backups.
Requirements
------------

Ansible 2.7 or newer.
Ansible 2.10 or newer.

Supported Platforms
-------------------

- [Debian - 10 (Buster)](https://wiki.debian.org/DebianBuster)
- [Debian - 11 (Bullseye)](https://wiki.debian.org/DebianBullseye)
- [Ubuntu - 18.04 (Bionic Beaver)](http://releases.ubuntu.com/18.04/)
- [Ubuntu - 20.04 (Focal Fossa)](http://releases.ubuntu.com/20.04/)
- [Ubuntu - 22.04 (Jammy Jellyfish)](http://releases.ubuntu.com/22.04/)

Role Variables
--------------
Expand Down
4 changes: 2 additions & 2 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ galaxy_info:
author: Nicolas Boutet
description: Configure backups.
license: MIT
min_ansible_version: 2.7
min_ansible_version: "2.10"
platforms:
- name: Ubuntu
versions:
- bionic
- focal
- jammy
- name: Debian
versions:
- bullseye
Expand Down
2 changes: 1 addition & 1 deletion molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- name: Converge
hosts: all
roles:
- role: ansible-role-backup
- role: boutetnico.backup
backup_extra_dir:
- /home/backupd/storage
backup_services:
Expand Down
4 changes: 2 additions & 2 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ platforms:
image: debian:10
- name: ansible-role-backup-debian-11
image: debian:11
- name: ansible-role-backup-ubuntu-1804
image: ubuntu:18.04
- name: ansible-role-backup-ubuntu-2004
image: ubuntu:20.04
- name: ansible-role-backup-ubuntu-2204
image: ubuntu:22.04

lint: |
yamllint .
Expand Down
24 changes: 14 additions & 10 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
---
- name: Ensure backup group exists
group:
ansible.builtin.group:
name: "{{ backup_group }}"
state: present

- name: Ensure backup user exists
user:
ansible.builtin.user:
append: "{{ true if backup_extra_groups | length > 0 else false }}"
group: "{{ backup_user }}"
groups: "{{ backup_extra_groups }}"
home: "{{ backup_home_dir }}"
name: "{{ backup_group }}"
shell: /bin/bash
state: present
when: backup_group != 'root'
when: backup_group != "root"

- name: Ensure dependencies are installed
apt:
ansible.builtin.apt:
name: "{{ backup_dependencies }}"
state: present
update_cache: true

- name: Create required directories
file:
ansible.builtin.file:
group: "{{ backup_group }}"
mode: 0750
owner: "{{ backup_user }}"
Expand All @@ -31,16 +31,18 @@
loop: "{{ [backup_scripts_dir, backup_temp_dir, backup_extra_dir] | flatten }}"

- name: Install backup scripts
template:
ansible.builtin.template:
dest: "{{ backup_scripts_dir }}/{{ item.name }}.sh"
group: "{{ backup_group }}"
mode: 0750
owner: "{{ backup_user }}"
src: "{{ item.script }}.j2"
with_items: "{{ backup_services }}"
loop: "{{ backup_services }}"
loop_control:
label: "{{ item.name }}"

- name: Install cron jobs of backuped services
cron:
- name: Install cron jobs to run backup scripts
ansible.builtin.cron:
day: "{{ item.cron.day | d(omit) }}"
hour: "{{ item.cron.hour | d(omit) }}"
job: >
Expand All @@ -52,5 +54,7 @@
state: present
user: "{{ backup_user }}"
weekday: "{{ item.cron.weekday | d(omit) }}"
with_items: "{{ backup_services }}"
loop: "{{ backup_services }}"
loop_control:
label: "{{ item.name }}"
when: item.cron is defined

0 comments on commit b7746b3

Please sign in to comment.