Skip to content

Commit

Permalink
[IMPROVEMENT] Upgrade unison binaries, improve installations method, …
Browse files Browse the repository at this point in the history
…reorganize unison roles
  • Loading branch information
pinkeen authored and krisdante committed May 26, 2020
1 parent c564d68 commit 7073eae
Show file tree
Hide file tree
Showing 22 changed files with 218 additions and 131 deletions.
2 changes: 2 additions & 0 deletions group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1656,3 +1656,5 @@ mageops_public_ip_v4_api_url: "{{ aws_use | ternary('http://169.254.169.254/late



mageops_unison_server_port: 5566

9 changes: 0 additions & 9 deletions roles/cs.unison-guest/defaults/main.yml

This file was deleted.

49 changes: 0 additions & 49 deletions roles/cs.unison-guest/tasks/main.yml

This file was deleted.

13 changes: 0 additions & 13 deletions roles/cs.unison-host/defaults/main.yml

This file was deleted.

35 changes: 0 additions & 35 deletions roles/cs.unison-host/tasks/main.yml

This file was deleted.

17 changes: 0 additions & 17 deletions roles/cs.unison-host/templates/project.prf

This file was deleted.

29 changes: 29 additions & 0 deletions roles/cs.unison-project/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
unison_project_name: "{{ mageops_project }}"
unison_project_slug: "{{ unison_project_name | trim | lower | regex_replace('[^a-z0-9]+', '_') }}"

unison_server_port: "{{ mageops_unison_server_port | default(5566) }}"
unison_server_address: "{{ hostvars[groups['vagrant'][0]]['ansible_host'] }}"

# Skip installation, just set up the project configuration
unison_project_skip_install: no

unison_project_local_path: "{{ playbook_dir }}/../projects/{{ unison_project_name }}"
unison_project_remote_path: "/{{ unison_project_name }}"

unison_project_config_dir: ~/.unison
unison_project_config_path: "{{ unison_project_config_dir }}/{{ unison_project_name }}.prf"

unison_project_ignore_names:
- ".idea"
- ".history"
- ".DS_Store"
- "._.DS_Store"
- "node_modules"
- ".php_cs.cache"
- ".tmp"
- "*.log"

unison_project_ignore_paths:
- "var/cache"
- "var/view_preprocessed"
- "var/log"
3 changes: 3 additions & 0 deletions roles/cs.unison-project/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies:
- role: cs.unison
when: not unison_project_skip_install | default(False)
15 changes: 15 additions & 0 deletions roles/cs.unison-project/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- name: Create unison config dir
file:
path: "{{ unison_project_config_dir }}"
state: directory

- name: Ensure local project dir exsits
file:
path: "{{ unison_project_local_path }}"
state: directory

- name: Create unison profile
template:
src: project.prf
dest: "{{ unison_project_config_path }}"

25 changes: 25 additions & 0 deletions roles/cs.unison-project/templates/project.prf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
root={{ unison_project_local_path | realpath }}
root=socket://{{ unison_server_address }}:{{ unison_server_port }}{{ unison_project_remote_path }}
label=Autoconfig for raccoon project {{ unison_project_name }}

auto=true
batch=true
fastcheck=default
retry=3


group=false
owner=false
dontchmod=false
perms=777
prefer={{ unison_project_local_path | realpath }}
silent=false
repeat=watch
stream=true

ignoreinodenumbers=true
ignorelocks=true

ignore = Name {{ '{' }}{{ unison_project_ignore_names | join(',') }}{{ '}' }}
ignore = Path {{ '{' }}{{ unison_project_ignore_paths | join(',') }}{{ '}' }}

14 changes: 14 additions & 0 deletions roles/cs.unison-server/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
unison_project_name: "{{ mageops_project }}"

unison_server_port: "{{ mageops_unison_server_port | default(5566) }}"

unison_server_version: 2.48.4
unison_server_tarball_url: "http://www.cis.upenn.edu/~bcpierce/unison/download/releases/unison-{{ unison_server_version }}/unison-{{ unison_server_version }}.tar.gz"

unison_server_user_create: yes
unison_server_user: "{{ magento_user }}"
unison_server_group: "{{ magento_group }}"

unison_server_working_dir: "{{ mageops_app_web_dir }}"
unison_server_project_dir: "{{ unison_server_working_dir }}/{{ unison_project_name }}"

File renamed without changes.
2 changes: 2 additions & 0 deletions roles/cs.unison-server/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dependencies:
- cs.unison
28 changes: 28 additions & 0 deletions roles/cs.unison-server/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
- name: Create user
when: unison_server_user_create
user:
name: "{{ unison_server_user }}"
state: present

- name: Ensure directories exist
file:
dest: "{{ item }}"
state: directory
mode: 0775
owner: "{{ unison_server_user }}"
group: "{{ unison_server_group }}"
with_items:
- "{{ unison_server_working_dir }}"
- "{{ unison_server_project_dir }}"

- name: Install unison service file
template:
src: unison.service
dest: /etc/systemd/system
notify: restart unison

- name: Start and enable unison
service:
name: unison
state: started
enabled: yes
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/unison -socket {{ unison_port }} -perms 0 -dontchmod true
ExecStart=/usr/bin/unison -socket {{ unison_server_port }} -perms 0 -dontchmod true
Restart=always
RestartSec=1
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=unison
User={{ unison_user }}
Group={{ unison_group }}
WorkingDirectory={{ unison_guest_working_dir }}
User={{ unison_server_user }}
Group={{ unison_server_group }}
WorkingDirectory={{ unison_server_working_dir }}
UMask=002

[Install]
Expand Down
3 changes: 3 additions & 0 deletions roles/cs.unison/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
unison_macos_brew_package: unison
unison_macos_brew_package_fsmonitor: autozimu/homebrew-formulas/unison-fsmonitor
unison_linux_inotify_max_user_watches: 1000000
3 changes: 3 additions & 0 deletions roles/cs.unison/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies:
- role: cs.repo-mageops
when: ansible_distribution | lower == 'centos'
17 changes: 17 additions & 0 deletions roles/cs.unison/tasks/install-centos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
- name: <CentOS> Increase max inotify watches for unison
sysctl:
name: fs.inotify.max_user_watches
value: "{{ unison_linux_inotify_max_user_watches | string }}"
reload: yes
state: present

- name: <CentOS> Make sure conflicting packages are absent
yum:
name: unison
state: absent

- name: <CentOS> Install latest unison version from MageOps RPM repo
yum:
name: unison-static
state: latest
enablerepo: mageops
44 changes: 44 additions & 0 deletions roles/cs.unison/tasks/install-macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
- name: <macOS> Check if homebrew package manager is present
command: brew config
failed_when: no
register: unison_brew_config_command

- name: <macOS> Warn user about being unable to install
when: unison_brew_config_command is failed
fail:
msg: |
====================================================================
= WARNING! Unison will NOT be installed! =
====================================================================
Automated installation on macOS requires that you have a functional
homebrew package manager installed.
Please go to https://brew.sh/ and follow the setup instructions.
Once you're done you can retry running this action or install them
manually:
$ brew install {{ unison_macos_brew_package_fsmonitor }} {{ unison_macos_brew_package }}
- name: <macOS> Install unison using homebrew
when: unison_brew_config_command is success
homebrew:
state: present
name:
- "{{ unison_macos_brew_package }}"
- "{{ unison_macos_brew_package_fsmonitor }}"
install_options:
- --force
- --force-bottle

# Homebrew module doesn't allow specifying link options
- name: <macOS> Make sure unison binaries are linked properly
when: unison_brew_config_command is success
command: >-
brew link --overwrite
{{ unison_macos_brew_package }}
{{ unison_macos_brew_package_fsmonitor }}
23 changes: 23 additions & 0 deletions roles/cs.unison/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
- name: Fail with warning about unspported OS
when: ansible_distribution | lower not in ['macosx', 'centos']
fail:
msg: |
====================================================================
= WARNING! Unison will not be installed! =
====================================================================
Automated installation is supported only on macOS and CentOS and your
system has been identified as: {{ ansible_distribution }}
You will have to install unison and fsmonitor manually yourself
to get continous file sync.
- name: Install unison client for macOS
import_tasks: install-macos.yml
when: ansible_distribution | lower == 'macosx'

- name: Install unison client for CentOS
import_tasks: install-centos.yml
when: ansible_distribution | lower == 'centos'

9 changes: 5 additions & 4 deletions vagrant.unison.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Run this playbook with --ask-sudo-pass
- hosts: "all"
# Best run this playbook with --ask-sudo-pass
- hosts: vagrant
become: yes
gather_facts: yes
roles:
- role: cs.unison-guest
- role: cs.unison-server

- hosts: localhost
connection: local
gather_facts: yes
roles:
- role: cs.unison-host
- role: cs.unison-project
Loading

0 comments on commit 7073eae

Please sign in to comment.