aboutsummaryrefslogtreecommitdiffstats
path: root/roles/shadowsocks/tasks/main.yml
blob: c911135e7c34a0f929cbdd39a235daaea9f40fec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
---
- name: install shadowsocks-libev
  pkgng:
    name: shadowsocks-libev
    state: present

- name: copy rc script
  copy:
    src: shadowsocks
    dest: /usr/local/etc/rc.d/shadowsocks
    mode: 0555
  notify: restart-shadowsocks

- name: setup configuration file
  vars:
    profile: "{{ item }}"
  template:
    src: config.json.j2
    dest: /usr/local/etc/shadowsocks-libev/{{ profile.name }}.json
    mode: 0640
  with_items: "{{ shadowsocks.profiles }}"
  notify: restart-shadowsocks

- name: setup rc.conf
  lineinfile:
    path: /etc/rc.conf
    regexp: '^shadowsocks_profiles=.*\b{{ item.name }}\b'
    line: 'shadowsocks_profiles="${shadowsocks_profiles} {{ item.name }}"'
  with_items: "{{ shadowsocks.profiles }}"

- name: enable service
  lineinfile:
    path: /etc/rc.conf
    regexp: '^shadowsocks_enable='
    line: 'shadowsocks_enable="YES"'
  notify: restart-shadowsocks

- name: start service
  service:
    name: shadowsocks
    state: started

- name: show client-side config
  vars:
    config: |
      "{"
          "local_port": 1080,
          "server": "{{ ansible_ssh_host }}",
          "server_port": {{ item.port }},
          "password": "{{ item.password }}",
          "method": "{{ shadowsocks.method }}"
      "}"
  debug:
    msg: "profile<{{ item.name }}>: {{ config.split('\n') }}"
  with_items: "{{ shadowsocks.profiles }}"