Skip to content

Commit

Permalink
Rework Update Handling (#37)
Browse files Browse the repository at this point in the history
Co-authored-by: Nikolaos Kakouros <[email protected]>
  • Loading branch information
simonspa and nkakouros authored Jun 6, 2020
1 parent b8bc0ad commit db108be
Show file tree
Hide file tree
Showing 13 changed files with 274 additions and 205 deletions.
78 changes: 59 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,96 @@
[![Build Status](https://travis-ci.com/nkakouros-original/ansible-role-nextcloud.svg?branch=master)](https://travis-ci.com/nkakouros-original/ansible-role-nextcloud)
[![Galaxy](https://img.shields.io/badge/galaxy-nkakouros.nextcloud-blue.svg)](https://galaxy.ansible.com/nkakouros/nextcloud/)

Ansible Role: Nextcloud
=========
# Ansible Role: Nextcloud

Installs and upgrades Nextcloud and apps. **It only does that**, it does not install a web server, a db server, etc.
Installs and upgrades Nextcloud and apps. **It only does that**, it does not
install a web server, a db server, etc.

Features
--------
## Features

This role allows you to:
- install, update and configure Nextcloud core
- install, update and configure Nextcloud apps available on the app store
- create and update users and groups

Requirements
------------
## Requirements

Ansible >= 2.7

While there are a bunch of other roles around to install Nextcloud, I did not found them useful as they try to do everything in one role, ie setup Apache, then MySQL, then install Nextcloud, etc. This might be useful for users who want to have a Nextcloud instance running as fast as possible. However, I find the approach too limiting as there are too many assumptions taking place.
While there are a bunch of other roles around to install Nextcloud, I did not
found them useful as they try to do everything in one role, ie setup Apache,
then MySQL, then install Nextcloud, etc. This might be useful for users who want
to have a Nextcloud instance running as fast as possible. However, I find the
approach too limiting as there are too many assumptions taking place.

This role does not care where you install Nextcloud. It only downloads, installs and configures Nextcloud itself. Its aim is to be used in a modular way alongside other roles. (Or at least it tries to make no assumptions. If you find any or cannot install nextcloud due to missing functionality, please open an issue or a PR. Currently it has been tested only on Ubuntu 16.04).
This role does not care where you install Nextcloud. It only downloads, installs
and configures Nextcloud itself. Its aim is to be used in a modular way
alongside other roles. (Or at least it tries to make no assumptions. If you find
any or cannot install nextcloud due to missing functionality, please open an
issue or a PR. Currently it has been tested only on Ubuntu 16.04).

See the [Example playbook](#example-playbook) on how a complete playbook that uses 3rd-party roles might look like.
See the [Example playbook](#example-playbook) on how a complete playbook that
uses 3rd-party roles might look like.

Versions
---
The python `listparser` module should be installed if you want to import feeds
into the `News` app from an opml file. E.g.:

- _Supported Nextcloud versions_: Each release of the role will support all officially supported Nextcloud versions, starting from version 14. That is, versions older than Nextcloud 14 will not be supported ever by this role (for instance Nextcloud 13, although it is supported officially as of this writing). Also, with each new major version of Nextcloud, the version that this role installs by default will be updated to match that latest major release.
```
pip install listaprser
```

- _Supported Ansible versions_: I am using an installation of Ansible that is daily checked out from their [development branch](https://github.com/ansible/ansible/tree/devel/). With each new Ansible stable version (currently 2.7), a new release of this role will be created that will be compatible with that new Ansible version. Work following such a release will take place with the in-development next version of Ansible and might use new Ansible features.

For this above reasons, role releases will have names such as `v14-2.7-1.0`, where:
## Versions

- _Supported Nextcloud versions_: Each release of the role will support all
officially supported Nextcloud versions, starting from version 14. That is,
versions older than Nextcloud 14 will not be supported ever by this role (for
instance Nextcloud 13, although it is supported officially as of this
writing). Also, with each new major version of Nextcloud, the version that
this role installs by default will be updated to match that latest major
release.

- _Supported Ansible versions_: I am using an installation of Ansible that is
daily checked out from their [development
branch](https://github.com/ansible/ansible/tree/devel/). With each new Ansible
stable version (currently 2.7), a new release of this role will be created
that will be compatible with that new Ansible version. Work following such
a release will take place with the in-development next version of Ansible and
might use new Ansible features.

For this above reasons, role releases will have names such as `v14-2.7-1.0`,
where:

- `14` is the version of Nextcloud that this role will install by default
- `2.7` is the Ansible version that the release will be compatible with
- `1.0` is semantic versioning of the role itself (reset when either of the two components above gets updated)
- `1.0` is semantic versioning of the role itself (reset when either of the two
components above gets updated)

The above release will of course also be compatible with later Ansible versions that are compatible with Ansible 2.7.
The above release will of course also be compatible with later Ansible versions
that are compatible with Ansible 2.7.

Role Variables
--------------

See [defaults/main.yml](https://github.com/nkakouros-original/ansible-role-nextcloud/blob/master/defaults/main.yml) for a full list of variables together with documentation on how to use them to configure this role.
See
[defaults/main.yml](https://github.com/nkakouros-original/ansible-role-nextcloud/blob/master/defaults/main.yml)
for a full list of variables together with documentation on how to use them to
configure this role.

Example Playbook
----------------

See [molecule/default/prepare.yml](molecule/default/prepare.yml) and [molecule/default/playbook.yml](molecule/default/playbook.yml) for a working example of how to use this role in conjuction with other roles to get a complete server environment that runs Nextcloud.
See [molecule/default/prepare.yml](molecule/default/prepare.yml) and
[molecule/default/playbook.yml](molecule/default/playbook.yml) for a working
example of how to use this role in conjuction with other roles to get a complete
server environment that runs Nextcloud.

License
-------

GPLv3

Author Information
------------------

Nikolaos Kakouros
63 changes: 34 additions & 29 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
nextcloud_enable: true
# Set this to 'no' to completely disable the role

# Installation {{{
nextcloud_version: 17
# The major nextcloud version to install. You can use this to upgrade to a new
# major version as well. Even if you set 'nextcloud_download_url' manually (see
Expand Down Expand Up @@ -53,13 +54,8 @@ nextcloud_database:

prefix: oc_
# Prefix for the nextcloud tables in the database.

nextcloud_admin_user: admin
# The name of the admin user

nextcloud_admin_pass: ''
# The password of the admin user. This variable should not be empty.

# }}}
# Core configuration {{{
# TODO make this part of nextcloud_config_system
nextcloud_enable_pretty_urls: true
# Set to yes to enable urls of the form https://example.org/calendar replacing
Expand All @@ -71,7 +67,37 @@ nextcloud_urls:
# This is a list of urls where your nextcloud installation should be accessible.
# You would normally need only one. If you specify more than one, the first one
# will be as the "main" one, for pretty urls, etc.
# }}}
# Users {{{
nextcloud_admin_user: admin
# The name of the admin user

nextcloud_admin_pass: ''
# The password of the admin user. This variable should not be empty.

nextcloud_users: []
# The ansible users to create, other than the admin.
# It is a list of hashes. Eg
#
# nextcloud_users:
# - name: alice
# pass: superstrongnot
# resetpassword: yes # reset the passsword every time the playbook is run
# display_name: Alice B. Charlie
# settings:
# - firstrunwizard:
# show: 0
# - calendar:
# showWeekNr: 'yes'
# app_config:
# ...
#
# App and core configuration happens per user. To find out what config options
# are available, either make the changes manually and then the oc_preferences
# table in your nextcloud database or use the `occ config:list` command on your
# server to get a listing of the current configuration options.
# }}}
# Apps {{{
nextcloud_remove_unknown_apps: false
# Setting to choose whether to remove or keep external apps which have not been
# installed through this role, but manually or via the Nextcloud admin interface
Expand Down Expand Up @@ -132,25 +158,4 @@ nextcloud_config: {}
# | regex_replace('^/')
# }}
# ```

nextcloud_users: []
# The ansible users to create, other than the admin.
# It is a list of hashes. Eg
#
# nextcloud_users:
# - name: alice
# pass: superstrongnot
# resetpassword: yes # reset the passsword every time the playbook is run
# display_name: Alice B. Charlie
# settings:
# - firstrunwizard:
# show: 0
# - calendar:
# showWeekNr: 'yes'
# app_config:
# ...
#
# App and core configuration happens per user. To find out what config options
# are available, either make the changes manually and then the oc_preferences
# table in your nextcloud database or use the `occ config:list` command on your
# server to get a listing of the current configuration options.
# }}}
5 changes: 2 additions & 3 deletions filter_plugins/opml.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ def read_opml(path):
import listparser
except Exception:
raise errors.AnsibleFilterError(
'the "opml" filter requires the \
"listparser" python module, install with `pip install \
listparser`'
'the "opml" filter requires the "listparser" python module,'
+ "install with `pip install listparser`"
)

try:
Expand Down
36 changes: 26 additions & 10 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
mode: g+w
listen: nextcloud update htaccess
- name: Update .htaccess file
command: ./occ maintenance:update:htaccess --no-interaction
command: php occ maintenance:update:htaccess --no-interaction
args:
chdir: "{{ nextcloud_installation_dir }}"
listen: nextcloud update htaccess
Expand All @@ -20,12 +20,28 @@
mode: g-w
listen: nextcloud update htaccess

- name: Set permissions on downloaded apps
file:
path: "{{ nextcloud_installation_dir }}/apps/"
mode: u=rwX,g=rX,o=rX
owner: "{{ nextcloud_file_owner }}"
group: "{{ nextcloud_file_owner }}"
state: directory
recurse: true
listen: set app files permissions
- name: Set file permissions on Nextcloud files
block:
- name: Set Nextcloud file permissions
file:
path: "{{ nextcloud_installation_dir }}"
mode: u=rwX,g=rX,o-rwx
owner: "{{ nextcloud_file_owner }}"
group: "{{ nextcloud_file_owner }}"
recurse: true
listen: nextcloud set file permissions
- name: Set permissions on installation directory
file:
path: "{{ nextcloud_installation_dir }}"
owner: root
group: "{{ nextcloud_file_owner }}"
mode: 0o750
state: directory
listen: nextcloud set file permissions
- name: Set permissions on htaccess file
file:
path: "{{ nextcloud_installation_dir }}/.htaccess"
owner: root
group: "{{ nextcloud_file_owner }}"
mode: 0o644
listen: nextcloud set file permissions
62 changes: 41 additions & 21 deletions tasks/apps/news.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
_nextcloud_news_users: >-
{{
nextcloud_users
| selectattr('app_config', 'defined')
| selectattr('app_config.news', 'defined')
| list
}}
Expand Down Expand Up @@ -188,45 +187,66 @@
delegate_to: localhost

# TODO: does not work, says method not allowed
# https://github.com/nextcloud/news/issues/711
# - name: Update feeds
# uri:
# method: PATCH
# url: >-
# {{
# nextcloud_urls[0]
# }}/apps/news/api/v1-2/feeds/{{
# {{ _nextcloud_api_url_news }}/feeds/{{
# (
# _nextcloud_existing_feeds.json.feeds
# | selectattr('url', 'equalto', item.url)
# _nextcloud_existing_feeds.results[
# (
# _nextcloud_news_users
# | map(attribute='name')
# | flatten
# ).index(item.0.name)
# ]['json']['feeds']
# | selectattr('url', 'equalto', item.1.url)
# | list
# | last
# )['id']
# }}
# body_format: json
# body:
# url: "{{ item.url }}"
# url: "{{ item.1.url }}"
# folderId: >-
# {{
# (
# _nextcloud_existing_folders.json.folders
# | selectattr('name', 'equalto', 'kde')
# _nextcloud_existing_folders.results[
# (
# _nextcloud_news_users
# | map(attribute='name')
# | flatten
# ).index(item.0.name)
# ]['json']['folders']
# | selectattr(
# 'name',
# 'equalto',
# item.1.folder
# | default([])
# | first
# | default('')
# )
# | list
# | first
# | last
# | default('__undefined__')
# )['id']
# | default(omit)
# }}
# headers:
# Authorization: Basic {{ (item.name + ':' + item.pass) | b64encode }}
# Authorization: Basic {{ (item.0.name + ':' + item.0.pass) | b64encode }}
# when: >-
# _nextcloud_existing_feeds.json.feeds
# | selectattr('url', 'equalto', item.url)
# _nextcloud_existing_feeds.results[
# (
# _nextcloud_news_users
# | map(attribute='name')
# | flatten
# ).index(item.0.name)
# ]['json']['feeds']
# | selectattr('url', 'equalto', item.1.url)
# | list
# | last
# | attr('folder')
# | default('__not_defined__')
# !=
# item.folder
# | default('__not_defined__')
# | length > 0
# register: result
# # changed_when: result is success
# loop: "{{ nextcloud_users[0]['app_config']['news']['feeds'] }}"
# changed_when: result is success
# loop: "{{ _nextcloud_news_users | subelements('app_config.news.feeds') }}"
# delegate_to: localhost
Loading

0 comments on commit db108be

Please sign in to comment.