Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 ansible playbooks #6

Merged
merged 13 commits into from
Sep 13, 2023
Merged

2 ansible playbooks #6

merged 13 commits into from
Sep 13, 2023

Conversation

Thechi2000
Copy link
Collaborator

Closes #2

@Thechi2000 Thechi2000 self-assigned this Sep 4, 2023
@Thechi2000 Thechi2000 linked an issue Sep 4, 2023 that may be closed by this pull request
3 tasks
Copy link
Collaborator

@codeofmochi codeofmochi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 🦀 I have a few general questions

@@ -0,0 +1,4 @@
# Those variables needs to be set on the server when accessed via SSH
# I.e. they will need to be in the .bashrc (or equivalent) file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to load from an adjacent .env instead? If so I think we should adopt it as convention

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using .env files seems a bit tricky, since Ansible is run over SSH and every tasks has its own shell. According to this post, we could manually parse a .env file and save its content into a variable, but it seems a bit dirty imo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should set those variables in the inventory.yaml, what do you think ?

hosts: all
tasks:
- name: Deploy
loop: "{{ [] }}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Info: what does this loop directive do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It executes the task for every item in the loop. Currently the loop is empty, but we'll fill it when we add services. The items of the loop are accessed with "{{ item }}"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to automate the loop at some point. See the find module

Comment on lines 41 to 56
- role: borgbase.ansible_role_borgbackup
borg_repository: "{{ ansible_env.BACKUP_DIR }}"
borgmatic_timer: cron
borgmatic_timer_hour: 0
borgmatic_timer_minute: 0
borg_source_directories:
- /var/lib/docker/volumes
borgmatic_hooks:
before_backup:
- echo "`date` - Starting backup."
postgresql_databases:
borg_retention_policy:
keep_hourly: 3
keep_daily: 7
keep_weekly: 4
keep_monthly: 6
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Info: what is a role in the context of ansible? It it mapped to a specific UNIX user or role?
Also, are we sure that backing up all volumes directly (i.e. from the filesystem) is safe w.r.t to consistency and integrity? See the PostgreSQL docs for instance:

An alternative backup strategy is to directly copy the files that PostgreSQL uses to store the data in the database; Section 19.2 explains where these files are located. You can use whatever method you prefer for doing file system backups; for example:

tar -cf backup.tar /usr/local/pgsql/data

There are two restrictions, however, which make this method impractical, or at least inferior to the pg_dump method:

The database server must be shut down in order to get a usable backup. Half-way measures such as disallowing all connections will not work (in part because tar and similar tools do not take an atomic snapshot of the state of the file system, but also because of internal buffering within the server). Information about stopping the server can be found in Section 19.5. Needless to say, you also need to shut down the server before restoring the data.

If you have dug into the details of the file system layout of the database, you might be tempted to try to back up or restore only certain individual tables or databases from their respective files or directories. This will not work because the information contained in these files is not usable without the commit log files, pg_xact/*, which contain the commit status of all transactions. A table file is only usable with this information. Of course it is also impossible to restore only a table and the associated pg_xact data because that would render all other tables in the database cluster useless. So file system backups only work for complete backup and restoration of an entire database cluster.

https://www.postgresql.org/docs/current/backup-file.html

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the databases we'll use the dedicated hooks (like the empty postgresql_databases on line 51). I forgot that databases would also be there, so I will restrict the source directories to the non-databases volumes (we'll fill it when adding services).

Comment on lines 12 to 13
- docker
- cron
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See if we need to list these deps explictly. We may need to setup git

- Fix variable names to be extracted from inventory
- Check borg repository existence before creation
- Fix BorgBackup inclusion to avoid multiple runs of the task
- Add task to install required packages
- Improve backup repository checks
- Decrease backup retention policy
- Move all docker operations to deploy.yaml
- Add missing packages
- Use explicit services list for loop
Comment on lines 14 to 18
- ansible-core
- docker.io
- borgbackup
- python3-docker
- python3-jsondiff
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider commenting what task requires each package

@Thechi2000 Thechi2000 merged commit 433d60a into main Sep 13, 2023
@Thechi2000 Thechi2000 deleted the 2-ansible-playbooks branch September 13, 2023 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ansible Playbooks
3 participants