From c102ff57bbde400e916d8469d9f53d963e81b428 Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Fri, 23 Apr 2021 16:04:49 -0400 Subject: [PATCH] fix dokuwiki role and add backup task --- all.yml | 5 +- roles/dokuwiki/tasks/backup.yml | 23 +++ roles/dokuwiki/tasks/dokuwiki.yml | 261 +++++++++++------------------- roles/dokuwiki/tasks/main.yml | 38 ++--- 4 files changed, 139 insertions(+), 188 deletions(-) create mode 100644 roles/dokuwiki/tasks/backup.yml diff --git a/all.yml b/all.yml index 9e5a855..263e9d7 100644 --- a/all.yml +++ b/all.yml @@ -10,11 +10,10 @@ - haproxy - hosts: - # TODO: fix dokuwiki role - #- dokuwiki + - dokuwiki - freshrss - gitweb - tags: containers + tags: containers, webserver roles: - webserver diff --git a/roles/dokuwiki/tasks/backup.yml b/roles/dokuwiki/tasks/backup.yml new file mode 100644 index 0000000..aa1e02e --- /dev/null +++ b/roles/dokuwiki/tasks/backup.yml @@ -0,0 +1,23 @@ +--- +- debug: + var: doku_path + +- name: make dokuwiki archive + community.general.archive: + dest: "{{ archive }}" + path: + - "{{ doku_path }}conf" + - "{{ doku_path }}data" + - "{{ doku_path }}lib/plugins" + +- name: copy archive to controller + fetch: + src: "{{ archive }}" + dest: "{{ output }}" + flat: yes + +- name: remove remote archive + file: + path: "{{ archive }}" + state: absent + diff --git a/roles/dokuwiki/tasks/dokuwiki.yml b/roles/dokuwiki/tasks/dokuwiki.yml index ef9aab9..a1455f4 100644 --- a/roles/dokuwiki/tasks/dokuwiki.yml +++ b/roles/dokuwiki/tasks/dokuwiki.yml @@ -1,165 +1,100 @@ --- # NOTE: https://wiki.alpinelinux.org/wiki/DokuWiki -- name: install dokuwiki to container - hosts: dokuwiki - tags: containers - - vars: - lighttpd_user: lighttpd - lighttpd_group: lighttpd - docroot: /var/www/localhost/htdocs - - doku_url: https://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz - doku_tar: /tmp/dokuwiki-stable.tgz - doku_dir: "{{ docroot }}/dokuwiki" - - use_backup: True - doku_backup_archive: ../data/dokuwiki_backup.tgz - backup_guard: ANSIBLE_BACKUP_GUARD - - tasks: - - # TODO: break out lighttpd default config to a separate playlist - - # - # lighttpd config - # - - - name: install packages - vars: - packages: - - lighttpd - - php7-common - - php7-session - - php7-iconv - - php7-json - - php7-gd - - php7-curl - - php7-xml - - php7-mysqli - - php7-imap - - php7-cgi - - php7-pdo - - php7-pdo_mysql - - php7-soap - - php7-xmlrpc - - php7-posix - - php7-mcrypt - - php7-gettext - - php7-ldap - - php7-ctype - - php7-dom - - fcgi - - tar - apk: - name: "{{ packages | join(' ') }}" - state: present - -# TODO: replace seperate template with 'line in file' -#$HTTP["url"] =~ "^/dokuwiki/(data|conf|bin|inc|vendor)/+." { -# url.access-deny = ("") -#} -# - name: copy lighttpd.conf -# copy: -# src: ../templates/lighttpd.conf.j2 -# dest: /etc/lighttpd/lighttpd.conf - - - name: ensure lighttpd service is started - service: - name: lighttpd - enabled: yes - state: started - - # - # dokuwiki config - # - - # TODO: this should be a separate play - - - name: test if dokuwiki was already installed - find: - paths: "{{ doku_dir }}" - pattern: README - register: doku_find_result - when: not use_backup - - - name: download dokuwiki stable - get_url: - url: "{{ doku_url }}" - dest: "{{ doku_tar }}" - when: not use_backup and doku_find_result.matched == 0 - - - name: make directory for dokiwiki in docroot - file: - path: "{{ doku_dir }}" - state: directory - owner: "{{ lighttpd_user }}" - group: "{{ lighttpd_group }}" - when: not use_backup and doku_find_result.matched == 0 - - - name: unarchive downloaded file - unarchive: - remote_src: yes - src: "{{ doku_tar }}" - dest: /tmp - owner: "{{ lighttpd_user }}" - group: "{{ lighttpd_group }}" - when: not use_backup and doku_find_result.matched == 0 - - - name: find doku temporary directory - find: - paths: /tmp/ - file_type: directory - pattern: "dokuwiki-20*" - use_regex: true - register: doku_tmp_dir - when: not use_backup - - - name: copy dokuwiki files to webroot - copy: - remote_src: yes - src: "{{ doku_tmp_dir.files[0].path }}/" - dest: "{{ doku_dir }}" - owner: "{{ lighttpd_user }}" - group: "{{ lighttpd_group }}" - when: not use_backup and doku_tmp_dir.matched > 0 - - # NOTE: this is only about 3.5MB - #- name: remove archive - # file: - # path: "{{ doku_tar }}" - # state: absent - - - name: remove temporary files - file: - path: "{{ doku_tmp_dir.files[0].path }}" - state: absent - when: not use_backup and doku_tmp_dir.matched > 0 - - # - # install backup data - # - - - name: test for backup guard - find: - path: "{{ doku_dir }}" - pattern: "{{ backup_guard }}" - register: backup_guard_present - - - name: extract backup archive - unarchive: - src: "{{ doku_backup_archive }}" - dest: "{{ docroot }}" - owner: "{{ lighttpd_user }}" - group: "{{ lighttpd_group }}" - when: use_backup and backup_guard_present.matched == 0 - - - name: add guard file to let ansible know backup is completed - file: - path: "{{ doku_dir }}/{{ backup_guard }}" - state: touch - when: use_backup and backup_guard_present.matched == 0 - - # TODO: add play for creating backup data - # TODO: split up plays and move to separate role - # TODO: remember to add custom plugins to backup + +- name: test if dokuwiki is already installed + find: + paths: "{{ doku_dir }}" + pattern: README + register: check_installed + +- set_fact: + install_dokuwiki: "{{ check_installed.matched == 0 }}" + +- name: install block + when: install_dokuwiki + vars: {} + block: + - name: add dokuwiki deny rules to lighttpd.conf + blockinfile: + path: /etc/lighttpd/lighttpd.conf + block: | + $HTTP["url"] =~ "^/dokuwiki/(data|conf|bin|inc|vendor)/+." { + url.access-deny = ("") + } + + - name: restart lighttpd + service: + name: lighttpd + enabled: yes + state: restarted + + - name: download dokuwiki stable + get_url: + url: "{{ doku_url }}" + dest: "{{ doku_tar }}" + + - name: make directory for dokiwiki in docroot + file: + path: "{{ doku_dir }}" + state: directory + owner: "{{ lighttpd_user }}" + group: "{{ lighttpd_group }}" + + - name: unarchive downloaded file + unarchive: + remote_src: yes + src: "{{ doku_tar }}" + dest: /tmp + owner: "{{ lighttpd_user }}" + group: "{{ lighttpd_group }}" + + - name: find doku temporary directory + find: + paths: /tmp/ + file_type: directory + pattern: "dokuwiki-20*" + use_regex: true + register: doku_tmp_dir + + - name: copy dokuwiki files to webroot + copy: + remote_src: yes + src: "{{ doku_tmp_dir.files[0].path }}/" + dest: "{{ doku_dir }}" + owner: "{{ lighttpd_user }}" + group: "{{ lighttpd_group }}" + + - name: remove archive + file: + path: "{{ doku_tar }}" + state: absent + + - name: remove temporary files + file: + path: "{{ doku_tmp_dir.files[0].path }}" + state: absent + + ## + ## install backup data + ## + + - name: test for backup guard + find: + path: "{{ doku_dir }}" + pattern: "{{ backup_guard }}" + register: backup_guard_present + + - name: extract backup archive + unarchive: + src: "{{ doku_backup_archive }}" + dest: "{{ doku_dir }}" + owner: "{{ lighttpd_user }}" + group: "{{ lighttpd_group }}" + when: use_backup and backup_guard_present.matched == 0 + + - name: add guard file to let ansible know backup is completed + file: + path: "{{ doku_dir }}/{{ backup_guard }}" + state: touch + when: use_backup and backup_guard_present.matched == 0 + diff --git a/roles/dokuwiki/tasks/main.yml b/roles/dokuwiki/tasks/main.yml index 9ad032c..83b067f 100644 --- a/roles/dokuwiki/tasks/main.yml +++ b/roles/dokuwiki/tasks/main.yml @@ -1,30 +1,24 @@ --- -#- name: include dokuwiki install task -# include_tasks: dokuwiki.yml +- name: include dokuwiki install task + vars: + lighttpd_user: lighttpd + lighttpd_group: lighttpd + docroot: /var/www/localhost/htdocs + + doku_url: https://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz + doku_tar: /tmp/dokuwiki-stable.tgz + doku_dir: "{{ docroot }}/dokuwiki" + + use_backup: True + doku_backup_archive: data/dokuwiki_backup.tgz + backup_guard: ANSIBLE_BACKUP_GUARD + import_tasks: dokuwiki.yml - name: backup block - when: "'backup' in ansible_run_tags" + include_tasks: backup.yml vars: output: /tmp/ archive: /tmp/dokuwiki_backup.tgz doku_path: /var/www/localhost/htdocs/dokuwiki/ - block: - - name: make dokuwiki archive - community.general.archive: - dest: "{{ archive }}" - path: - - "{{ doku_path }} + conf" - - "{{ doku_path }} + data" - - "{{ doku_path }} + lib/plugins" - - - name: copy archive to controller - fetch: - src: "{{ archive }}" - dest: "{{ output }}" - flat: yes - - - name: remove remote archive - file: - path: "{{ archive }}" - state: absent + when: "'backup' in ansible_run_tags"