Skip to content

Commit 8ad3cff

Browse files
committed
Add 'owncloud' role
- this role installs and configures ownCloud (http://owncloud.org/); - ownCloud by default uses nginx, php5 and mysql roles to configure the environment on local host, you can disable that and configure your own services; - by default ownCloud automatically finishes installation with admin username 'admin-$USER' and 'password' password, or random if role 'secret' is used, you can disable that behaviour using a variable; - you can use either MySQL (default), PostgreSQL or SQLite as the database backend;
1 parent 3da0d43 commit 8ad3cff

File tree

15 files changed

+500
-0
lines changed

15 files changed

+500
-0
lines changed

playbooks/owncloud.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
3+
- name: OwnCloud support
4+
hosts: ginas_owncloud
5+
sudo: yes
6+
7+
roles:
8+
- { role: owncloud }
9+
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
---
2+
3+
# --- Basic options ---
4+
5+
# Should ownCloud role manage it's own dependencies (nginx, php5, postgresql, mysql)?
6+
# If you want to setup them differently, you should change this to False
7+
owncloud_dependencies: True
8+
9+
# Domain that will be configured for ownCloud instance
10+
owncloud_domain: '{{ ansible_fqdn }}'
11+
12+
13+
# --- ownCloud source and deployment ---
14+
15+
# User and group that will be used for ownCloud instance
16+
owncloud_user: 'owncloud'
17+
owncloud_group: 'owncloud'
18+
owncloud_home: '/srv/users/{{ owncloud_user }}'
19+
20+
# Path where ownCloud data/ directory and files are stored
21+
owncloud_data_path: '/srv/lib/{{ owncloud_user }}/{{ owncloud_domain }}/data'
22+
23+
# Where ownCloud instance will be deployed (web root)
24+
owncloud_deploy_path: '/srv/www/{{ owncloud_user }}/sites/{{ owncloud_domain }}/public'
25+
26+
# What source should be used to get ownCloud files (upstream, githost, github, gitlab)
27+
owncloud_source: 'upstream'
28+
29+
# Default settings for ownCloud sources other than "upstream"
30+
# If you want to use that with github, you can create your ownCloud repository
31+
# as '<your username>/owncloud' with branch 'master'
32+
owncloud_deploy_user: 'git'
33+
owncloud_deploy_server: 'github.com'
34+
owncloud_deploy_repo: '{{ lookup("env","USER") }}/owncloud.git'
35+
owncloud_deploy_branch: 'master'
36+
37+
# OAuth token for GitHub / GitLab access, used to setup SSH deploy key
38+
owncloud_deploy_token: False
39+
40+
# Hash of different ownCloud sources
41+
owncloud_source_map:
42+
43+
# Official ownCloud upstream repository on GitHub (basic installation)
44+
upstream:
45+
url: 'https://github.com/owncloud/core.git'
46+
branch: 'stable6'
47+
48+
# A git repository configured on a host in the Ansible cluster, for example
49+
# with 'githost' role
50+
# Ansible will try and setup ssh public key of the 'owncloud' user as deploy
51+
# key on the server with git repository, using authorized_key module
52+
githost:
53+
url: '{{ owncloud_deploy_user }}@{{ owncloud_deploy_server }}:{{ owncloud_deploy_repo }}'
54+
branch: '{{ owncloud_deploy_branch }}'
55+
56+
# A git repository set up on GitHub, with deploy key configured through API
57+
# using OAuth token
58+
github:
59+
url: 'git@github.com:{{ owncloud_deploy_repo }}'
60+
branch: '{{ owncloud_deploy_branch }}'
61+
62+
# A git repository set up on a GitLab instance, with deploy key configured
63+
# through API using OAuth token
64+
gitlab:
65+
url: '{{ owncloud_deploy_user }}@{{ owncloud_deploy_server }}:{{ owncloud_deploy_repo }}'
66+
branch: '{{ owncloud_deploy_branch }}'
67+
68+
69+
# --- ownCloud database ---
70+
71+
# ownCloud recommends MySQL database as the default. Set to False to use SQLite
72+
owncloud_database: 'mysql'
73+
74+
owncloud_database_map:
75+
76+
# MySQL database on localhost (random password will be generated when using 'secret' role)
77+
mysql:
78+
dbtype: 'mysql'
79+
dbname: '{{ owncloud_user }}'
80+
dbuser: '{{ owncloud_user }}'
81+
dbpass: '{{ owncloud_dbpass | default("password") }}'
82+
dbhost: 'localhost'
83+
dbtableprefix: ''
84+
85+
# PostgreSQL database on localhost, connection through Unix socket, no default password
86+
postgresql:
87+
dbtype: 'pgsql'
88+
dbname: '{{ owncloud_user }}'
89+
dbuser: '{{ owncloud_user }}'
90+
dbpass: ''
91+
dbhost: '/var/run/postgresql'
92+
dbtableprefix: ''
93+
94+
95+
# --- ownCloud admin login / password ---
96+
97+
# Default admin username, in the form 'admin-$USER'
98+
# Set to False to disable automatic username and password
99+
owncloud_admin_username: 'admin-{{ lookup("env","USER") }}'
100+
101+
# Default admin password, will be randomly generated if 'secret' role is enabled
102+
owncloud_admin_password: 'password'
103+
104+
# Length of randomly generated admin password
105+
owncloud_password_length: '20'
106+
107+
# Should Ansible automatically open ownCloud page to finish setup on it's own?
108+
# Disabled if admin username is set to False
109+
owncloud_autosetup: True
110+
111+
112+
# --- ownCloud configuration ---
113+
114+
# Max upload size set in nginx and php5, with amount as M or G
115+
owncloud_upload_size: '128M'
116+
117+
# Output buffering set in php5, with amount set in megabytes
118+
owncloud_php5_output_buffering: '128'
119+
120+
# Max children processes to run in php5-fpm
121+
owncloud_php5_max_children: '50'
122+
123+
# At what time cron should execute background jobs
124+
owncloud_cron_minute: '*/15'
125+
126+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
3+
dependencies:
4+
5+
- role: mysql
6+
when: owncloud_dependencies is defined and owncloud_dependencies and
7+
owncloud_database is defined and owncloud_database == 'mysql'
8+
tags: owncloud
9+
10+
- role: postgresql
11+
when: owncloud_dependencies is defined and owncloud_dependencies and
12+
owncloud_database is defined and owncloud_database == 'postgresql'
13+
tags: owncloud
14+
15+
- role: php5
16+
php5_pools:
17+
- '{{ owncloud_php5_pool }}'
18+
when: owncloud_dependencies is defined and owncloud_dependencies
19+
tags: owncloud
20+
21+
- role: nginx
22+
nginx_servers:
23+
- '{{ owncloud_nginx_server }}'
24+
nginx_upstreams:
25+
- '{{ owncloud_nginx_upstream_php5 }}'
26+
when: owncloud_dependencies is defined and owncloud_dependencies
27+
tags: owncloud
28+
29+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
3+
- name: Install required packages for MySQL support
4+
apt: pkg={{ item }} state=latest install_recommends=no
5+
with_items: [ 'php5-mysql' ]
6+
tags: [ 'owncloud', 'mysql' ]
7+
8+
- name: Get default MySQL password
9+
set_fact:
10+
owncloud_database_password: '{{ owncloud_database_map[owncloud_database].dbpass }}'
11+
tags: [ 'owncloud', 'mysql' ]
12+
13+
- name: Lookup MySQL password if secrets/ directory is defined
14+
set_fact:
15+
owncloud_database_password: "{{ lookup('password', secret + '/credentials/' + ansible_fqdn + '/owncloud/mysql/' + owncloud_database_map[owncloud_database].dbuser + '/password length=' + mysql_password_length) }}"
16+
when: secret is defined
17+
tags: [ 'owncloud', 'mysql' ]
18+
19+
- name: Create ownCloud MySQL user
20+
mysql_user: name={{ owncloud_database_map[owncloud_database].dbuser }}
21+
password={{ owncloud_database_password }} state=present
22+
host='localhost' priv='{{ owncloud_database_map[owncloud_database].dbname }}.*:ALL'
23+
tags: [ 'owncloud', 'mysql' ]
24+
25+
- name: Create ownCloud database
26+
mysql_db: name={{ owncloud_database_map[owncloud_database].dbname }} state=present
27+
tags: [ 'owncloud', 'mysql' ]
28+
29+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
3+
- name: Setup cron service
4+
cron: name='ownCloud Background Jobs' minute={{ owncloud_cron_minute }} user={{ owncloud_user }}
5+
job='/usr/bin/php -f {{ owncloud_deploy_path }}/cron.php' cron_file='owncloud'
6+
tags: owncloud
7+
8+
- name: Setup logrotate for owncloud
9+
template: src=etc/logrotate.d/owncloud.j2 dest=/etc/logrotate.d/owncloud owner=root group=root mode=0644
10+
tags: owncloud
11+
12+
- name: Lookup admin password if secrets/ directory is defined
13+
set_fact:
14+
owncloud_admin_password: "{{ lookup('password', secret + '/credentials/' + ansible_fqdn + '/owncloud/admin/' + owncloud_admin_username + '/password length=' + owncloud_password_length) }}"
15+
when: secret is defined and owncloud_admin_username is defined and owncloud_admin_username
16+
tags: owncloud
17+
18+
- name: Check if ownCloud is configured
19+
stat: path={{ owncloud_deploy_path }}/config/config.php
20+
register: owncloud_config_file
21+
tags: owncloud
22+
23+
- name: Install ownCloud autoconfig file
24+
template: src=srv/www/sites/config/autoconfig.php.j2 dest={{ owncloud_deploy_path }}/config/autoconfig.php
25+
owner={{ owncloud_user }} group={{ owncloud_group }} mode=0660
26+
when: owncloud_config_file is defined and owncloud_config_file.stat.exists == False
27+
tags: owncloud
28+
29+
- name: Install ownCloud default config file
30+
template: src=srv/www/sites/config/config.default.php.j2 dest={{ owncloud_deploy_path }}/config/config.php
31+
owner={{ owncloud_user }} group={{ owncloud_group }} mode=0640
32+
when: owncloud_config_file is defined and owncloud_config_file.stat.exists == False
33+
tags: owncloud
34+
35+
- name: Use cron for background jobs (lib/private/...)
36+
lineinfile: dest={{ owncloud_deploy_path }}/lib/private/backgroundjob.php state=present regexp="return OC_Appconfig::getValue" line=" return OC_Appconfig::getValue( 'core', 'backgroundjobs_mode', 'cron' );"
37+
when: owncloud_config_file is defined and owncloud_config_file.stat.exists == False
38+
tags: owncloud
39+
40+
- name: Use cron for background jobs (settings/admin.php)
41+
lineinfile: dest={{ owncloud_deploy_path }}/settings/admin.php state=present regexp="'backgroundjobs_mode', OC_Appconfig::getValue" line="$tmpl->assign('backgroundjobs_mode', OC_Appconfig::getValue('core', 'backgroundjobs_mode', 'cron'));"
42+
when: owncloud_config_file is defined and owncloud_config_file.stat.exists == False
43+
tags: owncloud
44+
45+
- name: Flush handlers if automatic setup is requested
46+
meta: flush_handlers
47+
when: owncloud_config_file is defined and owncloud_config_file.stat.exists == False and
48+
owncloud_admin_username is defined and owncloud_admin_username and
49+
owncloud_autosetup is defined and owncloud_autosetup
50+
tags: owncloud
51+
52+
- name: Automatically finish setup if allowed
53+
uri: url=https://{{ owncloud_domain }}/index.php
54+
when: owncloud_config_file is defined and owncloud_config_file.stat.exists == False and
55+
owncloud_admin_username is defined and owncloud_admin_username and
56+
owncloud_autosetup is defined and owncloud_autosetup
57+
tags: owncloud
58+
59+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
3+
- name: Install required packages for PostgreSQL support
4+
apt: pkg={{ item }} state=latest install_recommends=no
5+
with_items: [ 'php5-pgsql' ]
6+
tags: [ 'owncloud', 'postgresql' ]
7+
8+
- name: Get default PostgreSQL password
9+
set_fact:
10+
owncloud_database_password: '{{ owncloud_database_map[owncloud_database].dbpass }}'
11+
tags: [ 'owncloud', 'postgresql' ]
12+
13+
- name: Create ownCloud PostgreSQL role
14+
postgresql_user: name={{ owncloud_database_map[owncloud_database].dbuser }} state=present
15+
sudo_user: 'postgres'
16+
tags: [ 'owncloud', 'postgresql' ]
17+
18+
- name: Create ownCloud database
19+
postgresql_db: name={{ owncloud_database_map[owncloud_database].dbname }} state=present owner={{ owncloud_database_map[owncloud_database].dbuser }}
20+
sudo_user: 'postgres'
21+
tags: [ 'owncloud', 'postgresql' ]
22+
23+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
3+
- name: Clone ownCloud source from deploy server
4+
git: repo={{ owncloud_source_map[owncloud_source].url }} dest={{ owncloud_home }}/{{ owncloud_deploy_repo }}
5+
bare=yes version={{ owncloud_source_map[owncloud_source].branch }} update=yes
6+
sudo_user: '{{ owncloud_user }}'
7+
register: owncloud_repo_updated
8+
tags: owncloud
9+
10+
- name: Checkout ownCloud to deployment path
11+
shell: GIT_WORK_TREE={{ owncloud_deploy_path }} git checkout --force {{ owncloud_source_map[owncloud_source].branch }}
12+
chdir={{ owncloud_home }}/{{ owncloud_deploy_repo }}
13+
sudo_user: '{{ owncloud_user }}'
14+
when: owncloud_repo_updated is defined and owncloud_repo_updated.changed
15+
tags: owncloud
16+
17+
- name: Point git work tree to separate .git directory
18+
lineinfile: "dest={{ owncloud_deploy_path }}/.git create=yes state=present regexp='^gitdir:' line='gitdir: {{ owncloud_home }}/{{ owncloud_deploy_repo }}'"
19+
sudo_user: '{{ owncloud_user }}'
20+
when: owncloud_repo_updated is defined and owncloud_repo_updated.changed
21+
tags: owncloud
22+
23+
- name: Checkout ownCloud submodules to deployment path
24+
shell: GIT_WORK_TREE={{ owncloud_deploy_path }} git submodule update --init --recursive --force chdir={{ owncloud_deploy_path }}
25+
sudo_user: '{{ owncloud_user }}'
26+
when: owncloud_repo_updated is defined and owncloud_repo_updated.changed
27+
tags: owncloud
28+
29+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
3+
- include: setup_environment.yml
4+
- include: setup_deploy_key.yml
5+
- include: deploy_owncloud.yml
6+
7+
- include: configure_mysql.yml
8+
when: owncloud_database is defined and owncloud_database == 'mysql'
9+
10+
- include: configure_postgresql.yml
11+
when: owncloud_database is defined and owncloud_database == 'postgresql'
12+
13+
- include: configure_owncloud.yml
14+
15+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
3+
- name: Slurp deploy key
4+
slurp: src={{ owncloud_home }}/.ssh/id_rsa.pub
5+
register: owncloud_deploy_key
6+
when: owncloud_deploy_key is undefined
7+
tags: owncloud
8+
9+
- name: Create hash variable with deploy key
10+
set_fact:
11+
owncloud_deploy_data:
12+
title: '{{ owncloud_user }}@{{ ansible_hostname }} deployed by Ansible'
13+
key: '{{ owncloud_deploy_key.content | b64decode | trim }}'
14+
when: owncloud_deploy_key is defined
15+
tags: owncloud
16+
17+
- name: Setup deploy key on ownCloud source server (githost)
18+
authorized_key: user={{ owncloud_deploy_user }} key='{{ owncloud_deploy_data.key }}'
19+
key_options='no-X11-forwarding,no-agent-forwarding,no-port-forwarding' state=present
20+
delegate_to: '{{ owncloud_deploy_server }}'
21+
when: owncloud_deploy_key is defined and
22+
owncloud_source is defined and
23+
owncloud_source == 'githost'
24+
tags: owncloud
25+
26+
- name: Setup deploy key on ownCloud source server (github)
27+
command: "curl --silent --header 'Authorization: token {{ owncloud_deploy_token }}' --data '{{ owncloud_deploy_data | to_nice_json }}' https://api.github.com/repos/{{ owncloud_deploy_repo | replace('.git','') }}/keys"
28+
changed_when: False
29+
when: owncloud_deploy_key is defined and
30+
owncloud_source is defined and
31+
owncloud_source == 'github'
32+
tags: owncloud
33+
34+
- name: Find id of ownCloud source project (gitlab)
35+
uri: >
36+
url=https://{{ owncloud_deploy_server }}/api/v3/projects/{{ owncloud_deploy_repo | replace('.git','') | replace('/','%2F') }}
37+
HEADER_PRIVATE-TOKEN={{ owncloud_deploy_token }}
38+
register: owncloud_gitlab
39+
when: owncloud_deploy_key is defined and
40+
owncloud_source is defined and
41+
owncloud_source == 'gitlab'
42+
tags: owncloud
43+
44+
- name: Setup deploy key on ownCloud source server (gitlab)
45+
uri: >
46+
url=https://{{ owncloud_deploy_server }}/api/v3/projects/{{ owncloud_gitlab.json.id }}/keys
47+
HEADER_PRIVATE-TOKEN={{ owncloud_deploy_token }} HEADER_Content-Type="application/json"
48+
status_code=201 method=POST body='{{ owncloud_deploy_data | to_nice_json }}'
49+
when: owncloud_deploy_key is defined and
50+
owncloud_source is defined and
51+
owncloud_source == 'gitlab'
52+
tags: owncloud
53+
54+

0 commit comments

Comments
 (0)