This repository contains Ansible roles for deploying, maintaining, and backing up a Nextcloud Docker instance. The roles included are:
Deploys a standard setup of nextcloud with a nextcloud-apache image, redis and mysql. No extra configuration is done.
The maintenance role includes tasks for routine maintenance of the Nextcloud instance, such as updating software and cleaning up logs.
The backup role includes tasks for backing up Nextcloud data and databases, ensuring data integrity and security.
Creates a dumb of a localy or nativ running mysql instance and deployes it in a docker mysql container.
- Ansible 2.9+
- Docker and Docker Compose
- Molecule 3.0+
- Python 3.11+
- Nginx-Proxy-Manager with Openresty
Run the following commands before editing code to run the python env and install ansible-molecule:
python3 -m venv env
source env/bin/activate
pip install -r requirements.txtTo install the ansible.community.archive modul.
ansible-galaxy collection install -r requirements.ymlCode Structure
.
├── BuildDockerTestImage/
│ ├── Dockerfile
│ └── initctl_faker
├── group_vars/
├── inventories/
│ └── hosts.yml
├── playbooks/
├── roles/
│ ├── deploy/
│ │ ├── tasks/
│ │ ├── handlers/
│ │ ├── molecule/
│ │ │ └── default/
│ │ │ ├── converge.yml
│ │ │ ├── molecule.yml
│ │ │ └── prepare.yml
│ │ └── templates/
│ ├── maintenance/
│ │ ├── tasks/
│ │ ├── handlers/
│ │ ├── molecule/
│ │ │ └── default/
│ │ │ ├── converge.yml
│ │ │ ├── molecule.yml
│ │ │ └── prepare.yml
│ │ └── templates/
│ ├── backup/
│ │ └── tasks/
│ └── migration/
│ ├── tasks/
│ └── vars/
├── ansible.cfg
├── requirements.txt
├── requirements.yml
└── vault.yml
Ensure the ansible.cfg file is present in the root of your project directory with the following settings:
[defaults]
inventory = ./inventories/hosts.yml
roles_path = ./rolesDefine your inventory in inventories/hosts.yml to specify the target hosts for Ansible playbooks.
- Define Variables: Ensure all required variables are set in
group_vars/all.yml. - Templates: Customize the templates in
roles/{{ role_name }}/templates/as needed.
To deploy Nextcloud, run the following command:
ansible-playbook playbooks/deploy.yml --ask-vault-passI recommand using ansible vault. Atleast the playbook already includes one. Create it in the repositorys root directory with the command:
ansible-vault create vault.ymlNow you can store your server passwords secure.
Example vault.yml:
vault_ansible_password: "somesecurepassword"I like to use the yml way of managing my hosts. Below is a simple example how to setup a inventory. Be care full what you name it though since the default name is set in the ansible.cfg to be inventories/hosts.yml.
Example inventories/host.yml:
all:
hosts:
127.1.1.1:
ansible_user: username # provide the username
# ansible_ssh_private_key_file: ~/.ssh/serversshkey # in case you use ssh key (you should)
ansible_become_pass: "{{ vault_ansible_password }}" #variable defiened in vault.yml that points to the password of the user
ansible_become_method: sudo
ansible_port: 22Testing with Molecule
Use the Dockerfile in the BuildDockerTestImage directory to build a testing image.
Build the Docker image:
docker build -t localhost/debian12-ansible:latest .In order to create a molecule test setup go into the roles directory you want to test. There you can execute the command:
molecule init scenario --driver-name docker defaultThis command calls the molecule plugin to create a scenario called default with docker as the driver that shell be used to create the test environment later while executing the molecule create command. It could also be aws, kubernetes or similar container Software tools.
Running Molecule Tests
Ensure your molecule/default/molecule.yml is configured to use the custom Docker image.
- Create instances:
molecule create | tee molecule_create.log - Run converge:
molecule converge | tee molecule_converge.log - Verify the Setup:
molecule verify | tee molecule_verify.log - Destroy instance:
molecule destroy
Feel free to open issues or submit pull requests with improvements or fixes. Contributions are always welcome!
- Installing molecule is way easier in a python virtual environment.
- Have docker on your host and remote system installed. It makes life easier.
This project is licensed under the MIT License - see the LICENSE file for details.