Skip to content

Commit

Permalink
Reworked task coding style.
Browse files Browse the repository at this point in the history
  • Loading branch information
ypid committed Sep 28, 2015
1 parent 4325575 commit 9ef0237
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 44 deletions.
2 changes: 1 addition & 1 deletion meta/ansigenome.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ ansigenome_info:

synopsis: |
This role installs and configures [Etherpad](http://etherpad.org/), an
on-line multiuser collabolative text editor. It will be installed behind
on-line multiuser collaborative text editor. It will be installed behind
`nginx` server with MySQL as a database backend.
153 changes: 110 additions & 43 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,53 +1,88 @@
---

- name: Install required Etherpad packages
apt: pkg={{ item }} state=latest install_recommends=no
apt:
pkg: '{{ item }}'
state: 'latest'
install_recommends: no
with_items:
- build-essential
- pkg-config
- libssl-dev
- libpq-dev
- curl
- git
- build-essential
- pkg-config
- libssl-dev
- libpq-dev
- curl
- git

- name: Install Abiword if enabled
apt: pkg=abiword state=latest install_recommends=no
apt:
pkg: 'abiword'
state: 'latest'
install_recommends: no
when: etherpad_abiword is defined and etherpad_abiword

- name: Make sure that directory for system users exists
file: path=/srv/users state=directory owner=root group=root mode=0751
file:
path: '/srv/users'
state: 'directory'
owner: 'root'
group: 'root'
mode: '0751'

- name: Create Etherpad system group
group: name={{ etherpad_group }} system=yes state=present
group:
name: '{{ etherpad_group }}'
system: yes
state: 'present'

- name: Create Etherpad user
user: name={{ etherpad_user }} group={{ etherpad_group }} home={{ etherpad_home }}
comment="Etherpad" system=yes state=present
user:
name: '{{ etherpad_user }}'
group: '{{ etherpad_group }}'
home: '{{ etherpad_home }}'
comment: 'Etherpad'
system: yes
state: 'present'

- name: Secure Etherpad home directory
file: path={{ etherpad_home }} state=directory
owner={{ etherpad_user }} group={{ etherpad_group }} mode=0750
file:
path: '{{ etherpad_home }}'
state: 'directory'
owner: '{{ etherpad_user }}'
group: '{{ etherpad_group }}'
mode: '0750'

- name: Clone Etherpad source code
git: repo={{ etherpad_source_address + '/' + etherpad_repository }}
dest={{ etherpad_sources + '/' + etherpad_repository }}
version={{ etherpad_version }} bare=yes update=yes
git:
repo: '{{ etherpad_source_address + "/" + etherpad_repository }}'
dest: '{{ etherpad_sources + "/" + etherpad_repository }}'
version: '{{ etherpad_version }}'
bare: yes
update: yes
sudo_user: '{{ etherpad_user }}'
register: etherpad_register_source

- name: Check if Etherpad is checked out
stat: path={{ etherpad_home + '/' + etherpad_repository }}
stat:
path: '{{ etherpad_home + "/" + etherpad_repository }}'
register: etherpad_register_directory

- name: Create Etherpad directory
file: path={{ etherpad_home + '/' + etherpad_repository }} state=directory
owner={{ etherpad_user }} group={{ etherpad_group }} mode=0755
file:
path: '{{ etherpad_home + "/" + etherpad_repository }}'
state: 'directory'
owner: '{{ etherpad_user }}'
group: '{{ etherpad_group }}'
mode: '0755'
when: (etherpad_register_source is defined and etherpad_register_source.changed == True) or
(etherpad_register_directory is defined and etherpad_register_directory.stat.exists == False)

- name: Prepare Etherpad worktree
template: src=srv/users/etherpad/etherpad-lite/git.j2 dest={{ etherpad_home + '/' + etherpad_repository }}/.git
owner={{ etherpad_user }} group={{ etherpad_group }} mode=0644
template:
src: 'srv/users/etherpad/etherpad-lite/git.j2'
dest: '{{ etherpad_home + "/" + etherpad_repository }}/.git'
owner: '{{ etherpad_user }}'
group: '{{ etherpad_group }}'
mode: '0644'
when: (etherpad_register_source is defined and etherpad_register_source.changed == True) or
(etherpad_register_directory is defined and etherpad_register_directory.stat.exists == False)

Expand All @@ -67,59 +102,91 @@

- name: Lookup MySQL password if secrets/ directory is defined
set_fact:
etherpad_mysql_database_password: "{{ lookup('password', secret + '/credentials/' + ansible_fqdn + '/mysql/' + etherpad_database_config[etherpad_database].username + '/password') }}"
etherpad_mysql_database_password: '{{ lookup("password", secret + "/credentials/" + ansible_fqdn + "/mysql/" + etherpad_database_config[etherpad_database].username + "/password") }}'
when: (secret is defined and secret) and (etherpad_database is defined and etherpad_database == 'mysql')

- name: Generate Etherpad session key
set_fact:
etherpad_session_key: "{{ lookup('password', secret + '/credentials/' + ansible_fqdn + '/etherpad/session_key chars=ascii,numbers,digits,hexdigits length=30') }}"
etherpad_session_key: '{{ lookup("password", secret + "/credentials/" + ansible_fqdn + "/etherpad/session_key chars=ascii,numbers,digits,hexdigits length=30") }}'
when: secret is defined and secret

- name: Generate Etherpad configuration
template: src=srv/users/etherpad/etherpad-lite/settings.json.j2
dest={{ etherpad_home + '/' + etherpad_repository }}/settings.json
owner={{ etherpad_user }} group={{ etherpad_group }} mode=0644
template:
src: 'srv/users/etherpad/etherpad-lite/settings.json.j2'
dest: '{{ etherpad_home + "/" + etherpad_repository }}/settings.json'
owner: '{{ etherpad_user }}'
group: '{{ etherpad_group }}'
mode: '0644'
notify: [ 'Restart etherpad-lite' ]

- name: Reserve Etherpad port
template: src=etc/services.d/50_etherpad-lite.j2 dest=/etc/services.d/50_etherpad-lite
owner=root group=root mode=0644
template:
src: 'etc/services.d/50_etherpad-lite.j2'
dest: '/etc/services.d/50_etherpad-lite'
owner: 'root'
group: 'root'
mode: '0644'
notify: [ 'Assemble services.d' ]

- name: Create log directory
file: state=directory path=/var/log/etherpad-lite
owner={{ etherpad_user }} group=adm mode=0755
file:
path: '/var/log/etherpad-lite'
state: 'directory'
owner: '{{ etherpad_user }}'
group: 'adm'
mode: '0755'

- name: Configure etherpad-lite system service
template: src={{ item }}.j2 dest=/{{ item }} owner=root group=root mode=0644
with_items: [ 'etc/default/etherpad-lite', 'etc/logrotate.d/etherpad-lite' ]
template:
src: '{{ item }}.j2'
dest: '/{{ item }}'
owner: 'root'
group: 'root'
mode: '0644'
with_items:
- 'etc/default/etherpad-lite'
- 'etc/logrotate.d/etherpad-lite'

- name: Install etherpad-lite init script
template: src=etc/init.d/etherpad-lite.j2 dest=/etc/init.d/etherpad-lite
owner=root group=root mode=0755
template:
src: 'etc/init.d/etherpad-lite.j2'
dest: '/etc/init.d/etherpad-lite'
owner: 'root'
group: 'root'
mode: '0755'
notify: [ 'Restart etherpad-lite' ]

- name: Enable etherpad-lite service
service: name=etherpad-lite enabled=yes
service:
name: 'etherpad-lite'
enabled: yes

- name: Install Etherpad dependencies
command: bin/installDeps.sh chdir={{ etherpad_home + '/' + etherpad_repository }}
creates={{ etherpad_home }}/.node-gyp
command: bin/installDeps.sh
args:
chdir: '{{ etherpad_home + "/" + etherpad_repository }}'
creates: '{{ etherpad_home }}/.node-gyp'
sudo_user: '{{ etherpad_user }}'

- name: Install sqlite3 for Etherpad
npm: path={{ etherpad_home + '/' + etherpad_repository }} state=present
production=yes name=sqlite3
npm:
name: 'sqlite3'
path: '{{ etherpad_home + "/" + etherpad_repository }}'
state: 'present'
production: yes
sudo_user: '{{ etherpad_user }}'
notify: [ 'Restart etherpad-lite' ]
when: etherpad_database == 'sqlite'

- name: Manage Etherpad plugins
npm: path={{ etherpad_home + '/' + etherpad_repository }} state=present
production=yes name='ep_{{ item }}'
npm:
name: 'sqlite3'
path: '{{ etherpad_home + "/" + etherpad_repository }}'
state: 'present'
production: yes
name: 'ep_{{ item }}'
with_items: etherpad_plugins
sudo_user: '{{ etherpad_user }}'
notify: [ 'Restart etherpad-lite' ]
when: etherpad_plugins is defined and etherpad_plugins


0 comments on commit 9ef0237

Please sign in to comment.