ownCloud & Ansible: Introduction and How To

First, I would like to announce the ownCloud Ansible GitHub organisation:

A huge thank you goes out to Robert who developed all roles and custom modules to make this work.

There you can find Ansible roles to set up ownCloud on CentOS 7 and Ubuntu 18.04.
CentOS 8 still need some adjustments to the package installation in the playbooks in order to work.

The roles are being automatically tested, however if you find errors please report them in the respective issue trackers.

There is some documentation available on https://owncloud-ansible.github.io/

Try it out, feedback welcome!

And now I would like to dive straight into a quick how to:

The easiest and fastest way to get a working single instance setup on CentOS is with the help of the playground repo:

  1. Prerequisites:
  • Linux workstation
  • Ansible installed
  • git installed on the Linux workstation
  • SSH access from the Linux workstation to the server you want to install ownCloud on
  • An administrative user on that server, either root or a user that doesn’t need a password to run commands with sudo: <username> ALL=(ALL) NOPASSWD: ALL
  • The ownCloud-server-to-be needs internet access (see footnote)
  • If your server is CentOS the following packages need to be installed beforehand: centos-release-scl, gcc (to get an up to date PHP version and be able to compile additionally required PHP modules)
  1. Clone the following repo: https://github.com/owncloud-ansible/playground
  2. cd into the directory where you cloned the repo to
  3. Run ansible-galaxy install -r roles/requirements.yml --force to download the additional roles. By default these will be installed in ~/.ansible/roles/.
  4. Delete the example inventories you don’t need. For example the vagrant and ubuntu-minimal in the inventories folder, if you’re going to install on CentOS
  5. Adjust the hosts file in the centos inventory like so:
db1 ansible_host=<ip.add.re.ss of your server>

redis1 ansible_host=<ip.add.re.ss of your server>

owncloud1 ansible_host=<ip.add.re.ss of your server>

ansible_user=<admin user>
# add the two following lines if your not using root to log in

For a single instance setup you can also put the variable ansible_host into the all:vars section. For a more in depth explanation of this please see at the bottom of this post.

  1. Adjust inventories/centos7/group_vars/database.yml
# For security reasons you should set a strong password
# for the owncloud DB and root user!
mariadb_root_password: <set a secure MySQL root pw>

  - name: owncloud
    host: localhost
    password: <set a secure owncloud db pw>
    priv: "owncloud.*:ALL"


Here you can overwrite any of the defaults set in .ansible/roles/mariadb/defaults/main.yml

  1. Adjust inventories/centos7/group_vars/owncloud.yml, a minimal configuration could look like:
owncloud_version: "10.4"
owncloud_fqdn: <your.owncloud.fqdn.tld>
owncloud_admin_password: <set a secure pw>
owncloud_db_password: <set the pw from the file above>

  - servername: "<your.owncloud.fqdn.tld>"
    documentroot: "/var/www/owncloud"

You will probably want to define an SSL site here as well, check the apache ansible role defaults for details

In this file you can overwrite any of the defaults defined for the roles in .ansible/roles/{owncloud,php,apache}/defaults/main.yml.

So I would strongly recommend to read these defaults and make adjustments to your needs:
owncloud ansible role defaults
php ansible role defaults

For point 7 and 8 you need to understand Ansible inventories, have a look in their documentation for more information: https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html

  1. Finally run ansible-playbook -i inventories/centos7/hosts playbooks/setup.yml and watch it install ownCloud

There are ways to automatically install ownCloud apps, set various ownCloud settings, make it a multi-instance setup, … The possibilities are endless :wink:

But just a few default settings you need to know:

  • ownCloud admin user is admin
  • Ansible creates a user.config.php
  • The data folder is set up to be in /usr/local/src/owncloud/data
  • The config folder is in /usr/local/src/owncloud/config
  • The writeable apps folder is /usr/local/src/owncloud/custom
  • The previous three folders are symlinked from the main ownCloud installation folder /var/www/owncloud

Explanation to the internet access of the ownCloud server: The ansible-playbook will download and install various packages from the repositories, download the ownCloud tarball and connect to the marketplace for additional apps. If your server is on an intranet without access to the public internet, you can also configure your server to use your own repository mirrors. Additionally you can also provide the ownCloud tarball from your local Ansible host filesystem. For marketplace apps you can provide an alternative download URL.

Explanation for the hosts file - 6:

  • This is mapping the different ansible roles to individual hosts. This allows also a rapid multi-instance setup, when defining different hosts for each role. However various other variables in the playbooks also need to be adjusted for the multi-instance setup to work through ansible.
  • A new trick that I like to use to install everything locally, is to not define where any of the hosts are at all and just put ansible_connection=local in the [all:vars] section. This will, instead of try to use SSH just install everything locally.