Admin How To
42 | DECEMBER 2017 | OPEN SOURCE FOR YOU | http://www.OpenSourceForU.com
become_method: sudo
gather_facts: true
tags: [backup]
vars:
piwigo_dest: “/var/www/html”
tasks:
- name: Create target directory
file:
path: “{{ piwigo_dest }}/gallery/backup”
state: directory - name: Backup folder
archive:
path: “{{ piwigo_dest }}/gallery/piwigo”
dest: “{{ piwigo_dest }}/gallery/backup/piwigo-
backup-{{ ansible_date_time.epoch }}.tar.bz2” - name: Dump database
mysql_db:
name: piwigo
state: dump
target: “{{ piwigo_dest }}/gallery/backup/piwigo-{{
ansible_date_time.epoch }}.sql”
The above playbook can be invoked as follows:
$ ansible-playbook -i inventory/kvm/inventory playbooks/
configuration/piwigo.yml --tags backup -K
Two backup files that were created from executing the
above playbook are piwigo-1510053932.sql and piwigo-
backup-1510053932.tar.bz2.
Cleaning up
You can uninstall the entire Piwigo installation using an
Ansible playbook. This has to happen in the reverse order.
You have to remove Piwigo first, followed by PHP, MySQL
and Apache. A playbook to do this is included in the
playbooks/admin folder and given below for reference:
---
- name: Uninstall Piwigo
hosts: ubuntu
become: yes
become_method: sudo
gather_facts: true
tags: [uninstall]
vars:
piwigo_dest: “/var/www/html”
tasks:
- name: Delete piwigo folder
file:
path: “{{ piwigo_dest }}/gallery”
state: absent
- name: Drop database
mysql_db:
name: piwigo
state: absent - name: Uninstall PHP packages
package:
name: “{{ item }}”
state: absent
with_items: - php5-mysql
- php5
- name: Stop the database server
service:
name: mysql
state: stopped - name: Uninstall MySQL packages
package:
name: “{{ item }}”
state: absent
with_items: - python-mysqldb
- mysql-client
- mysql-server
- name: Stop the web server
service:
name: apache2
state: stopped - name: Uninstall apache2
package:
name: “{{ item }}”
state: absent
with_items: - apache2
The above playbook can be invoked as follows:
$ ansible-playbook -i inventory/kvm/inventory playbooks/admin/
uninstall-piwigo.yml -K
You can visit http://piwigo.org/ for more documentation.
By: Shakthi Kannan
The author is a free software enthusiast and blogs at
shakthimaan.com.