Skip to content

Making Duplicity use venvs. #1547

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

Merged
merged 8 commits into from
Mar 27, 2024
7 changes: 6 additions & 1 deletion docs/roles/debian/duplicity.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ Role to install and configure [the Duplicity backup engine](https://duplicity.us
```yaml
---
duplicity:
# Location of Duplicity installation and components.
venv_path: "/home/{{ user_provision.username }}/duplicity"
venv_command: /usr/bin/python3 -m venv
install_username: "{{ user_provision.username }}"
# Duplicity configuration
backend: s3 # currently also support b2 for Backblaze
access_key_id: "somekey"
secret_access_key: "somesecret"
backend_url: "s3-eu-west-1.amazonaws.com"
s3_options: "--s3-european-buckets --s3-use-glacier-ir" # see the --s3 options in the documentation - https://duplicity.us/stable/duplicity.1.html#options
s3_options: "--s3-use-glacier-ir" # see the --s3 options in the documentation - https://duplicity.us/stable/duplicity.1.html#options
bucketname: "somebucket"
dirs:
- name: "/boot"
Expand Down
1 change: 1 addition & 0 deletions docs/roles/debian/mysql_server_oracle_ce.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Installs MySQL Server 5.7.
mysql_long_query_time: 4
mysql_server_oracle_ce_key: "8C718D3B5072E1F5" # archive key - see https://dev.mysql.com/doc/refman/8.0/en/gpg-key-archived-packages.html
mysql_server_oracle_ce_key_server: keyserver.ubuntu.com

```

<!--ENDROLEVARS-->
6 changes: 6 additions & 0 deletions roles/debian/ansible/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@
state: latest
virtualenv: "{{ ce_ansible.venv_path | default(_venv_path) }}"
virtualenv_command: "{{ ce_ansible.venv_command | default(_venv_command) }}"
become_user: "{{ ce_ansible.install_username | default(_install_username) }}"
become: true

- name: Install Ansible.
ansible.builtin.pip:
name:
- ansible
virtualenv: "{{ ce_ansible.venv_path | default(_venv_path) }}"
virtualenv_command: "{{ ce_ansible.venv_command | default(_venv_command) }}"
become_user: "{{ ce_ansible.install_username | default(_install_username) }}"
become: true

- name: Install linters.
ansible.builtin.pip:
Expand All @@ -55,6 +59,8 @@
- yamllint
virtualenv: "{{ ce_ansible.venv_path | default(_venv_path) }}"
virtualenv_command: "{{ ce_ansible.venv_command | default(_venv_command) }}"
become_user: "{{ ce_ansible.install_username | default(_install_username) }}"
become: true
when: ce_ansible.linters.enabled

- name: Ensure Ansible venv permissions.
Expand Down
2 changes: 2 additions & 0 deletions roles/debian/ce_provision/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@
- pyopenssl
virtualenv: "{{ _venv_path }}"
virtualenv_command: "{{ _venv_command }}"
become_user: "{{ ce_provision.install_username | default(_install_username) }}"
become: true

- name: Ensure Ansible venv permissions.
ansible.builtin.file:
Expand Down
7 changes: 6 additions & 1 deletion roles/debian/duplicity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ Role to install and configure [the Duplicity backup engine](https://duplicity.us
```yaml
---
duplicity:
# Location of Duplicity installation and components.
venv_path: "/home/{{ user_provision.username }}/duplicity"
venv_command: /usr/bin/python3 -m venv
install_username: "{{ user_provision.username }}"
# Duplicity configuration
backend: s3 # currently also support b2 for Backblaze
access_key_id: "somekey"
secret_access_key: "somesecret"
backend_url: "s3-eu-west-1.amazonaws.com"
s3_options: "--s3-european-buckets --s3-use-glacier-ir" # see the --s3 options in the documentation - https://duplicity.us/stable/duplicity.1.html#options
s3_options: "--s3-use-glacier-ir" # see the --s3 options in the documentation - https://duplicity.us/stable/duplicity.1.html#options
bucketname: "somebucket"
dirs:
- name: "/boot"
Expand Down
7 changes: 6 additions & 1 deletion roles/debian/duplicity/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
---
duplicity:
# Location of Duplicity installation and components.
venv_path: "/home/{{ user_provision.username }}/duplicity"
venv_command: /usr/bin/python3 -m venv
install_username: "{{ user_provision.username }}"
# Duplicity configuration
backend: s3 # currently also support b2 for Backblaze
access_key_id: "somekey"
secret_access_key: "somesecret"
backend_url: "s3-eu-west-1.amazonaws.com"
s3_options: "--s3-european-buckets --s3-use-glacier-ir" # see the --s3 options in the documentation - https://duplicity.us/stable/duplicity.1.html#options
s3_options: "--s3-use-glacier-ir" # see the --s3 options in the documentation - https://duplicity.us/stable/duplicity.1.html#options
bucketname: "somebucket"
dirs:
- name: "/boot"
Expand Down
3 changes: 0 additions & 3 deletions roles/debian/duplicity/meta/main.yml

This file was deleted.

50 changes: 43 additions & 7 deletions roles/debian/duplicity/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,51 @@
- name: Ensure duplicity is installed.
---
- name: Ensure system Duplicity is not installed.
ansible.builtin.apt:
pkg: duplicity
state: present
when: ansible_distribution_major_version | int >= 12
state: absent

- name: Ensure duplicity is installed.
- name: Ensure Duplicity is not installed globally with pip or pip3 on older versions of Debian.
ansible.builtin.pip:
name: duplicity
executable: pip3
state: present
name:
- duplicity
state: absent
executable: "{{ item }}"
when: ansible_distribution_major_version | int < 12
with_items:
- pip
- pip3
failed_when: false # don't stop the build if there's no system pip

# Install Python applications.
- name: Set up Python venv variables.
ansible.builtin.set_fact:
_venv_path: "{{ duplicity.venv_path }}"
_venv_command: "{{ duplicity.venv_command }}"
_install_username: "{{ duplicity.install_username }}"

- name: Ensure pip is at latest version.
ansible.builtin.pip:
name:
- pip
state: latest
virtualenv: "{{ duplicity.venv_path | default(_venv_path) }}"
virtualenv_command: "{{ duplicity.venv_command | default(_venv_command) }}"
become_user: "{{ duplicity.install_username | default(_install_username) }}"
become: true

- name: Install python_boto.
ansible.builtin.include_role:
name: debian/python_boto

- name: Install Duplicity and dependencies.
ansible.builtin.pip:
name:
- fasteners
- duplicity
virtualenv: "{{ duplicity.venv_path | default(_venv_path) }}"
virtualenv_command: "{{ duplicity.venv_command | default(_venv_command) }}"
become_user: "{{ duplicity.install_username | default(_install_username) }}"
become: true

- name: Create install dir.
ansible.builtin.file:
Expand Down
4 changes: 2 additions & 2 deletions roles/debian/duplicity/templates/duplicity_backup-b2.j2
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ for dir in ${DIRS[@]}; do
fi

DEST=b2://$B2_KEY_ID:$B2_SECRET_KEY@{{ duplicity.bucketname }}$dir
/usr/local/bin/duplicity $backup_options $extra_options $dir $DEST || exit 1
{{ _venv_path }}/bin/duplicity $backup_options $extra_options $dir $DEST || exit 1

if [ $REMOVE_OLD_BACKUPS -eq 1 ]; then
# Do some maintenance on the remote end to clean up old backups
echo "Performing routine maintenance on $dir..."
/usr/local/bin/duplicity $maintenance_options $DEST || exit 1
{{ _venv_path }}/bin/duplicity $maintenance_options $DEST || exit 1
fi
done

Expand Down
4 changes: 2 additions & 2 deletions roles/debian/duplicity/templates/duplicity_backup-s3.j2
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ for dir in ${DIRS[@]}; do
fi

DEST=s3://{{ duplicity.backend_url }}/{{ duplicity.bucketname }}$dir
/usr/local/bin/duplicity $backup_options $extra_options $dir $DEST || exit 1
{{ _venv_path }}/bin/duplicity $backup_options $extra_options $dir $DEST || exit 1

if [ $REMOVE_OLD_BACKUPS -eq 1 ]; then
# Do some maintenance on the remote end to clean up old backups
echo "Performing routine maintenance on $dir..."
/usr/local/bin/duplicity $maintenance_options $DEST || exit 1
{{ _venv_path }}/bin/duplicity $maintenance_options $DEST || exit 1
fi
done

Expand Down
2 changes: 1 addition & 1 deletion roles/debian/duplicity/templates/duplicity_clean-b2.j2
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ DIRS=(
for dir in ${DIRS[@]}; do
echo "Cleaning up $dir..."
DEST=b2://$B2_KEY_ID:$B2_SECRET_KEY@{{ duplicity.bucketname }}$dir
/usr/local/bin/duplicity $cleanup_options $DEST || exit 1
{{ _venv_path }}/bin/duplicity $cleanup_options $DEST || exit 1
done

unset PASSPHRASE
Expand Down
2 changes: 1 addition & 1 deletion roles/debian/duplicity/templates/duplicity_clean-s3.j2
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ DIRS=(
for dir in ${DIRS[@]}; do
echo "Cleaning up $dir..."
DEST=s3://{{ duplicity.backend_url }}/{{ duplicity.bucketname }}$dir
/usr/local/bin/duplicity $cleanup_options $DEST || exit 1
{{ _venv_path }}/bin/duplicity $cleanup_options $DEST || exit 1
done

unset PASSPHRASE
Expand Down
2 changes: 1 addition & 1 deletion roles/debian/duplicity/templates/duplicity_restore-b2.j2
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ mkdir -p $RESTORE_DIR
for dir in ${DIRS[@]}; do
echo "Restoring $dir..."
DEST=b2://$B2_KEY_ID:$B2_SECRET_KEY@{{ duplicity.bucketname }}$dir
/usr/local/bin/duplicity restore $RESTORE_OPTIONS $DEST $RESTORE_DIR$dir
{{ _venv_path }}/bin/duplicity restore $RESTORE_OPTIONS $DEST $RESTORE_DIR$dir
done

unset PASSPHRASE
Expand Down
2 changes: 1 addition & 1 deletion roles/debian/duplicity/templates/duplicity_restore-s3.j2
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ mkdir -p $RESTORE_DIR
for dir in ${DIRS[@]}; do
echo "Restoring $dir..."
DEST=s3://{{ duplicity.backend_url }}/{{ duplicity.bucketname }}$dir
/usr/local/bin/duplicity restore $RESTORE_OPTIONS $DEST $RESTORE_DIR$dir
{{ _venv_path }}/bin/duplicity restore $RESTORE_OPTIONS $DEST $RESTORE_DIR$dir
done

unset PASSPHRASE
Expand Down
9 changes: 1 addition & 8 deletions roles/debian/ldap_server/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,10 @@
pkg: ["libsasl2-dev", "libssl-dev", "python3-dev"] # python-ldap needs some dev packages
state: present

- name: Install python-ldap with pip3.
ansible.builtin.pip:
name: python-ldap
executable: pip3
when: ansible_distribution_major_version | int < 12

- name: Ensure python3-ldap is installed with apt.
- name: Ensure python3-ldap is installed.
ansible.builtin.apt:
pkg: python3-ldap
state: present
when: ansible_distribution_major_version | int >= 12

- name: Create the slapd config file.
ansible.builtin.template:
Expand Down
9 changes: 1 addition & 8 deletions roles/debian/mysql_client/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,10 @@
install_packages:
- python3-pip

- name: Ensure PyMySQL is installed with pip3.
ansible.builtin.pip:
name: pymysql
executable: pip3
when: ansible_distribution_major_version | int < 12

- name: Ensure PyMySQL is installed with apt.
- name: Ensure PyMySQL is installed.
ansible.builtin.apt:
pkg: python3-pymysql
state: present
when: ansible_distribution_major_version | int >= 12

- name: Copy debian.cnf credentials file.
ansible.builtin.template:
Expand Down
1 change: 1 addition & 0 deletions roles/debian/mysql_server_oracle_ce/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Installs MySQL Server 5.7.
mysql_long_query_time: 4
mysql_server_oracle_ce_key: "8C718D3B5072E1F5" # archive key - see https://dev.mysql.com/doc/refman/8.0/en/gpg-key-archived-packages.html
mysql_server_oracle_ce_key_server: keyserver.ubuntu.com

```

<!--ENDROLEVARS-->
9 changes: 1 addition & 8 deletions roles/debian/nginx/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,10 @@
install_packages:
- python3-pip

- name: Ensure passlib is installed with pip3.
ansible.builtin.pip:
name: passlib
executable: pip3
when: ansible_distribution_major_version | int < 12

- name: Ensure python3-passlib is installed with apt.
- name: Ensure python3-passlib is installed.
ansible.builtin.apt:
pkg: python3-passlib
state: present
when: ansible_distribution_major_version | int >= 12

- name: Copy main nginx config.
ansible.builtin.template:
Expand Down
2 changes: 2 additions & 0 deletions roles/debian/python_boto/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
name: "{{ _boto3_install_package }}"
virtualenv: "{{ python_boto.venv_path | default(_venv_path) }}"
virtualenv_command: "{{ python_boto.venv_command | default(_venv_command) }}"
become_user: "{{ python_boto.install_username | default(_install_username) }}"
become: true

- name: Ensure Ansible venv permissions.
ansible.builtin.file:
Expand Down
Loading