Skip to content

Commit 7073eae

Browse files
pinkeenkrisdante
authored andcommittedMay 26, 2020
[IMPROVEMENT] Upgrade unison binaries, improve installations method, reorganize unison roles
1 parent c564d68 commit 7073eae

File tree

22 files changed

+218
-131
lines changed

22 files changed

+218
-131
lines changed
 

‎group_vars/all.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1656,3 +1656,5 @@ mageops_public_ip_v4_api_url: "{{ aws_use | ternary('http://169.254.169.254/late
16561656

16571657

16581658

1659+
mageops_unison_server_port: 5566
1660+

‎roles/cs.unison-guest/defaults/main.yml

-9
This file was deleted.

‎roles/cs.unison-guest/tasks/main.yml

-49
This file was deleted.

‎roles/cs.unison-host/defaults/main.yml

-13
This file was deleted.

‎roles/cs.unison-host/tasks/main.yml

-35
This file was deleted.

‎roles/cs.unison-host/templates/project.prf

-17
This file was deleted.
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
unison_project_name: "{{ mageops_project }}"
2+
unison_project_slug: "{{ unison_project_name | trim | lower | regex_replace('[^a-z0-9]+', '_') }}"
3+
4+
unison_server_port: "{{ mageops_unison_server_port | default(5566) }}"
5+
unison_server_address: "{{ hostvars[groups['vagrant'][0]]['ansible_host'] }}"
6+
7+
# Skip installation, just set up the project configuration
8+
unison_project_skip_install: no
9+
10+
unison_project_local_path: "{{ playbook_dir }}/../projects/{{ unison_project_name }}"
11+
unison_project_remote_path: "/{{ unison_project_name }}"
12+
13+
unison_project_config_dir: ~/.unison
14+
unison_project_config_path: "{{ unison_project_config_dir }}/{{ unison_project_name }}.prf"
15+
16+
unison_project_ignore_names:
17+
- ".idea"
18+
- ".history"
19+
- ".DS_Store"
20+
- "._.DS_Store"
21+
- "node_modules"
22+
- ".php_cs.cache"
23+
- ".tmp"
24+
- "*.log"
25+
26+
unison_project_ignore_paths:
27+
- "var/cache"
28+
- "var/view_preprocessed"
29+
- "var/log"

‎roles/cs.unison-project/meta/main.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dependencies:
2+
- role: cs.unison
3+
when: not unison_project_skip_install | default(False)
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
- name: Create unison config dir
2+
file:
3+
path: "{{ unison_project_config_dir }}"
4+
state: directory
5+
6+
- name: Ensure local project dir exsits
7+
file:
8+
path: "{{ unison_project_local_path }}"
9+
state: directory
10+
11+
- name: Create unison profile
12+
template:
13+
src: project.prf
14+
dest: "{{ unison_project_config_path }}"
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
root={{ unison_project_local_path | realpath }}
2+
root=socket://{{ unison_server_address }}:{{ unison_server_port }}{{ unison_project_remote_path }}
3+
label=Autoconfig for raccoon project {{ unison_project_name }}
4+
5+
auto=true
6+
batch=true
7+
fastcheck=default
8+
retry=3
9+
10+
11+
group=false
12+
owner=false
13+
dontchmod=false
14+
perms=777
15+
prefer={{ unison_project_local_path | realpath }}
16+
silent=false
17+
repeat=watch
18+
stream=true
19+
20+
ignoreinodenumbers=true
21+
ignorelocks=true
22+
23+
ignore = Name {{ '{' }}{{ unison_project_ignore_names | join(',') }}{{ '}' }}
24+
ignore = Path {{ '{' }}{{ unison_project_ignore_paths | join(',') }}{{ '}' }}
25+
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
unison_project_name: "{{ mageops_project }}"
2+
3+
unison_server_port: "{{ mageops_unison_server_port | default(5566) }}"
4+
5+
unison_server_version: 2.48.4
6+
unison_server_tarball_url: "http://www.cis.upenn.edu/~bcpierce/unison/download/releases/unison-{{ unison_server_version }}/unison-{{ unison_server_version }}.tar.gz"
7+
8+
unison_server_user_create: yes
9+
unison_server_user: "{{ magento_user }}"
10+
unison_server_group: "{{ magento_group }}"
11+
12+
unison_server_working_dir: "{{ mageops_app_web_dir }}"
13+
unison_server_project_dir: "{{ unison_server_working_dir }}/{{ unison_project_name }}"
14+

‎roles/cs.unison-server/meta/main.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dependencies:
2+
- cs.unison

‎roles/cs.unison-server/tasks/main.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
- name: Create user
2+
when: unison_server_user_create
3+
user:
4+
name: "{{ unison_server_user }}"
5+
state: present
6+
7+
- name: Ensure directories exist
8+
file:
9+
dest: "{{ item }}"
10+
state: directory
11+
mode: 0775
12+
owner: "{{ unison_server_user }}"
13+
group: "{{ unison_server_group }}"
14+
with_items:
15+
- "{{ unison_server_working_dir }}"
16+
- "{{ unison_server_project_dir }}"
17+
18+
- name: Install unison service file
19+
template:
20+
src: unison.service
21+
dest: /etc/systemd/system
22+
notify: restart unison
23+
24+
- name: Start and enable unison
25+
service:
26+
name: unison
27+
state: started
28+
enabled: yes

‎roles/cs.unison-guest/templates/unison.service ‎roles/cs.unison-server/templates/unison.service

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ After=network.target
44

55
[Service]
66
Type=simple
7-
ExecStart=/usr/bin/unison -socket {{ unison_port }} -perms 0 -dontchmod true
7+
ExecStart=/usr/bin/unison -socket {{ unison_server_port }} -perms 0 -dontchmod true
88
Restart=always
99
RestartSec=1
1010
StandardOutput=syslog
1111
StandardError=syslog
1212
SyslogIdentifier=unison
13-
User={{ unison_user }}
14-
Group={{ unison_group }}
15-
WorkingDirectory={{ unison_guest_working_dir }}
13+
User={{ unison_server_user }}
14+
Group={{ unison_server_group }}
15+
WorkingDirectory={{ unison_server_working_dir }}
1616
UMask=002
1717

1818
[Install]

‎roles/cs.unison/defaults/main.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
unison_macos_brew_package: unison
2+
unison_macos_brew_package_fsmonitor: autozimu/homebrew-formulas/unison-fsmonitor
3+
unison_linux_inotify_max_user_watches: 1000000

‎roles/cs.unison/meta/main.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dependencies:
2+
- role: cs.repo-mageops
3+
when: ansible_distribution | lower == 'centos'
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
- name: <CentOS> Increase max inotify watches for unison
2+
sysctl:
3+
name: fs.inotify.max_user_watches
4+
value: "{{ unison_linux_inotify_max_user_watches | string }}"
5+
reload: yes
6+
state: present
7+
8+
- name: <CentOS> Make sure conflicting packages are absent
9+
yum:
10+
name: unison
11+
state: absent
12+
13+
- name: <CentOS> Install latest unison version from MageOps RPM repo
14+
yum:
15+
name: unison-static
16+
state: latest
17+
enablerepo: mageops
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
- name: <macOS> Check if homebrew package manager is present
2+
command: brew config
3+
failed_when: no
4+
register: unison_brew_config_command
5+
6+
- name: <macOS> Warn user about being unable to install
7+
when: unison_brew_config_command is failed
8+
fail:
9+
msg: |
10+
11+
====================================================================
12+
= WARNING! Unison will NOT be installed! =
13+
====================================================================
14+
15+
Automated installation on macOS requires that you have a functional
16+
homebrew package manager installed.
17+
18+
Please go to https://brew.sh/ and follow the setup instructions.
19+
20+
Once you're done you can retry running this action or install them
21+
manually:
22+
23+
$ brew install {{ unison_macos_brew_package_fsmonitor }} {{ unison_macos_brew_package }}
24+
25+
- name: <macOS> Install unison using homebrew
26+
when: unison_brew_config_command is success
27+
homebrew:
28+
state: present
29+
name:
30+
- "{{ unison_macos_brew_package }}"
31+
- "{{ unison_macos_brew_package_fsmonitor }}"
32+
install_options:
33+
- --force
34+
- --force-bottle
35+
36+
# Homebrew module doesn't allow specifying link options
37+
- name: <macOS> Make sure unison binaries are linked properly
38+
when: unison_brew_config_command is success
39+
command: >-
40+
brew link --overwrite
41+
{{ unison_macos_brew_package }}
42+
{{ unison_macos_brew_package_fsmonitor }}
43+
44+

‎roles/cs.unison/tasks/main.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
- name: Fail with warning about unspported OS
2+
when: ansible_distribution | lower not in ['macosx', 'centos']
3+
fail:
4+
msg: |
5+
6+
====================================================================
7+
= WARNING! Unison will not be installed! =
8+
====================================================================
9+
10+
Automated installation is supported only on macOS and CentOS and your
11+
system has been identified as: {{ ansible_distribution }}
12+
13+
You will have to install unison and fsmonitor manually yourself
14+
to get continous file sync.
15+
16+
- name: Install unison client for macOS
17+
import_tasks: install-macos.yml
18+
when: ansible_distribution | lower == 'macosx'
19+
20+
- name: Install unison client for CentOS
21+
import_tasks: install-centos.yml
22+
when: ansible_distribution | lower == 'centos'
23+

‎vagrant.unison.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
# Run this playbook with --ask-sudo-pass
2-
- hosts: "all"
1+
# Best run this playbook with --ask-sudo-pass
2+
- hosts: vagrant
33
become: yes
4+
gather_facts: yes
45
roles:
5-
- role: cs.unison-guest
6+
- role: cs.unison-server
67

78
- hosts: localhost
89
connection: local
910
gather_facts: yes
1011
roles:
11-
- role: cs.unison-host
12+
- role: cs.unison-project

‎vagrant.yml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- role: cs.vagrant-sudo
1515
- role: geerlingguy.composer
1616
- role: cs.nodejs
17+
- role: cs.unison-server
1718
- role: cs.authorize-local-keys
1819
authorize_local_keys_for_users:
1920
- root

0 commit comments

Comments
 (0)
Please sign in to comment.