diff --git a/handlers/main.yml b/handlers/main.yml index bf62063..628e0e4 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,2 +1,6 @@ --- # handlers file for snowflake +- name: restart snowflake + ansible.builtin.service: + name: snowflake-proxy + state: restarted diff --git a/tasks/arch.yml b/tasks/arch.yml index 15cd670..25fa9f4 100644 --- a/tasks/arch.yml +++ b/tasks/arch.yml @@ -8,61 +8,3 @@ package: name: "{{ snowflake_utils_arch }}" state: present - -- name: Add the user - ansible.builtin.user: - name: "{{ snowflake_user }}" - create_home: true - state: present - -- name: Clone snowflake repo - ansible.builtin.git: - repo: 'https://git.torproject.org/pluggable-transports/snowflake.git' - dest: /home/{{ snowflake_user }}/repo - update: "{{ snowflake_update }}" - register: clone_git - -- name: go get - command: go get - args: - warn: no - chdir: /home/{{ snowflake_user }}/repo/proxy - register: go_get - when: clone_git is changed - -- name: go build - command: go build - args: - warn: no - chdir: /home/{{ snowflake_user }}/repo/proxy - register: go_build - when: clone_git is changed - -- name: Copy binary file to /usr/bin/ - ansible.builtin.copy: - src: /home/{{ snowflake_user }}/repo/proxy/proxy - dest: /usr/bin/ - mode: a+x - remote_src: yes - -- name: Add unit systemd - template: - src: "../templates/{{ item }}.j2" - dest: "/etc/systemd/system/{{ item }}" - mode: 0644 - with_items: - - snowflake-proxy.service - -- name: Enable service snowflake-proxy - ansible.builtin.systemd: - name: snowflake-proxy - enabled: yes - -- name: Just force systemd to reread configs - ansible.builtin.systemd: - daemon_reload: yes - -- name: Start/restart service snowflake - ansible.builtin.service: - name: snowflake-proxy - state: restarted diff --git a/tasks/debian-bullseye.yml b/tasks/debian-bullseye.yml index aaaa48f..f540a18 100644 --- a/tasks/debian-bullseye.yml +++ b/tasks/debian-bullseye.yml @@ -1,3 +1,9 @@ +--- +- name: Update cache + ansible.builtin.apt: + update_cache: yes + cache_valid_time: 3600 + - name: Install golang package: name: "{{ snowflake_packages_deb }}" @@ -8,61 +14,3 @@ package: name: "{{ snowflake_utils }}" state: present - -- name: Add the user - ansible.builtin.user: - name: "{{ snowflake_user }}" - create_home: true - state: present - -- name: Clone snowflake repo - ansible.builtin.git: - repo: 'https://git.torproject.org/pluggable-transports/snowflake.git' - dest: /home/{{ snowflake_user }}/repo - update: "{{ snowflake_update }}" - register: clone_git - -- name: go get - command: go get - args: - warn: no - chdir: /home/{{ snowflake_user }}/repo/proxy - register: go_get - when: clone_git is changed - -- name: go build - command: go build - args: - warn: no - chdir: /home/{{ snowflake_user }}/repo/proxy - register: go_build - when: clone_git is changed - -- name: Copy binary file to /usr/bin/ - ansible.builtin.copy: - src: /home/{{ snowflake_user }}/repo/proxy/proxy - dest: /usr/bin/ - mode: a+x - remote_src: yes - -- name: Add unit systemd - template: - src: "../templates/{{ item }}.j2" - dest: "/etc/systemd/system/{{ item }}" - mode: 0644 - with_items: - - snowflake-proxy.service - -- name: Enable service snowflake-proxy - ansible.builtin.systemd: - name: snowflake-proxy - enabled: yes - -- name: Just force systemd to reread configs - ansible.builtin.systemd: - daemon_reload: yes - -- name: Start/restart service snowflake - ansible.builtin.service: - name: snowflake-proxy - state: restarted diff --git a/tasks/debian.yml b/tasks/debian.yml index 2cbc282..fdad60d 100644 --- a/tasks/debian.yml +++ b/tasks/debian.yml @@ -1,3 +1,9 @@ +--- +- name: Update cache + ansible.builtin.apt: + update_cache: yes + cache_valid_time: 3600 + - name: Add backports repository apt_repository: repo: "deb http://deb.debian.org/debian buster-backports main" @@ -14,62 +20,3 @@ package: name: "{{ snowflake_utils }}" state: present - -- name: Add the user - ansible.builtin.user: - name: "{{ snowflake_user }}" - create_home: true - state: present - -- name: Clone snowflake repo - ansible.builtin.git: - repo: 'https://git.torproject.org/pluggable-transports/snowflake.git' - dest: /home/{{ snowflake_user }}/repo - update: "{{ snowflake_update }}" - register: clone_git - -- name: go get - command: go get - args: - warn: no - chdir: /home/{{ snowflake_user }}/repo/proxy - register: go_get - when: clone_git is changed - -- name: go build - command: go build - args: - warn: no - chdir: /home/{{ snowflake_user }}/repo/proxy - register: go_build - when: clone_git is changed - -- name: Copy binary file to /usr/bin/ - ansible.builtin.copy: - src: /home/{{ snowflake_user }}/repo/proxy/proxy - dest: /usr/bin/ - mode: a+x - remote_src: yes - -- name: Add unit systemd - template: - src: "../templates/{{ item }}.j2" - dest: "/etc/systemd/system/{{ item }}" - mode: 0644 - with_items: - - snowflake-proxy.service - -- name: Enable service snowflake-proxy - ansible.builtin.systemd: - name: snowflake-proxy - enabled: yes - -- name: Just force systemd to reread configs - ansible.builtin.systemd: - daemon_reload: yes - -- name: Start/restart service snowflake - ansible.builtin.service: - name: snowflake-proxy - state: restarted - diff --git a/tasks/fedora.yml b/tasks/fedora.yml index c7c54e1..297dbd0 100644 --- a/tasks/fedora.yml +++ b/tasks/fedora.yml @@ -8,62 +8,3 @@ package: name: "{{ snowflake_utils_fedora }}" state: present - -- name: Add the user - ansible.builtin.user: - name: "{{ snowflake_user }}" - create_home: true - state: present - -- name: Clone snowflake repo - ansible.builtin.git: - repo: 'https://git.torproject.org/pluggable-transports/snowflake.git' - dest: /home/{{ snowflake_user }}/repo - update: "{{ snowflake_update }}" - register: clone_git - -- name: go get - command: go get - args: - warn: no - chdir: /home/{{ snowflake_user }}/repo/proxy - register: go_get - when: clone_git is changed - -- name: go build - command: go build - args: - warn: no - chdir: /home/{{ snowflake_user }}/repo/proxy - register: go_build - when: clone_git is changed - -- name: Copy binary file to /usr/bin/ - ansible.builtin.copy: - src: /home/{{ snowflake_user }}/repo/proxy/proxy - dest: /usr/bin/ - mode: a+x - remote_src: yes - -- name: Add unit systemd - template: - src: "../templates/{{ item }}.j2" - dest: "/etc/systemd/system/{{ item }}" - mode: 0644 - with_items: - - snowflake-proxy.service - -- name: Enable service snowflake-proxy - ansible.builtin.systemd: - name: snowflake-proxy - enabled: yes - - -- name: Just force systemd to reread configs - ansible.builtin.systemd: - daemon_reload: yes - -- name: Start/restart service snowflake - ansible.builtin.service: - name: snowflake-proxy - state: restarted diff --git a/tasks/linux-common.yml b/tasks/linux-common.yml new file mode 100644 index 0000000..3e8823a --- /dev/null +++ b/tasks/linux-common.yml @@ -0,0 +1,55 @@ +--- +- name: Add the user + ansible.builtin.user: + name: "{{ snowflake_user }}" + create_home: true + state: present + +- name: Clone snowflake repo + ansible.builtin.git: + repo: 'https://git.torproject.org/pluggable-transports/snowflake.git' + dest: /home/{{ snowflake_user }}/repo + update: "{{ snowflake_update }}" + register: clone_git + +- name: go get + command: go get + args: + chdir: /home/{{ snowflake_user }}/repo/proxy + register: go_get + when: clone_git is changed + +- name: go build + command: go build + args: + chdir: /home/{{ snowflake_user }}/repo/proxy + register: go_build + when: clone_git is changed + +- name: Copy binary file to /usr/bin/ + ansible.builtin.copy: + src: /home/{{ snowflake_user }}/repo/proxy/proxy + dest: /usr/bin/ + mode: a+x + remote_src: yes + notify: restart snowflake + +- name: Add unit systemd + template: + src: "../templates/{{ item }}.j2" + dest: "/etc/systemd/system/{{ item }}" + mode: 0644 + with_items: + - snowflake-proxy.service + notify: restart snowflake + +- name: Enable service snowflake-proxy + ansible.builtin.systemd: + name: snowflake-proxy + enabled: yes + state: started + +- name: Just force systemd to reread configs + ansible.builtin.systemd: + daemon_reload: yes + diff --git a/tasks/main.yml b/tasks/main.yml index 95e29e9..772dca5 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -16,14 +16,18 @@ - ansible_distribution == 'Ubuntu' - ansible_distribution_release == 'focal' or ansible_distribution_release == 'jammy' -- include_tasks: freebsd.yml - when: - - ansible_distribution == 'FreeBSD' - - ansible_distribution_release == '13.0-RELEASE' - - include_tasks: arch.yml when: - ansible_distribution == 'Archlinux' - include_tasks: fedora.yml when: ansible_os_family == 'RedHat' + +- include_tasks: linux-common.yml + when: ansible_distribution != 'FreeBSD' + + +- include_tasks: freebsd.yml + when: + - ansible_distribution == 'FreeBSD' + - ansible_distribution_release == '13.0-RELEASE' diff --git a/tasks/ubuntu.yml b/tasks/ubuntu.yml index 898b2ff..f8910f0 100644 --- a/tasks/ubuntu.yml +++ b/tasks/ubuntu.yml @@ -12,61 +12,3 @@ package: name: "{{ snowflake_utils }}" state: present - -- name: Add the user - ansible.builtin.user: - name: "{{ snowflake_user }}" - create_home: true - state: present - -- name: Clone snowflake repo - ansible.builtin.git: - repo: 'https://git.torproject.org/pluggable-transports/snowflake.git' - dest: /home/{{ snowflake_user }}/repo - update: "{{ snowflake_update }}" - register: clone_git - -- name: go get - command: go get - args: - warn: no - chdir: /home/{{ snowflake_user }}/repo/proxy - register: go_get - when: clone_git is changed - -- name: go build - command: go build - args: - warn: no - chdir: /home/{{ snowflake_user }}/repo/proxy - register: go_build - when: clone_git is changed - -- name: Copy binary file to /usr/bin/ - ansible.builtin.copy: - src: /home/{{ snowflake_user }}/repo/proxy/proxy - dest: /usr/bin/ - mode: a+x - remote_src: yes - -- name: Add unit systemd - template: - src: "../templates/{{ item }}.j2" - dest: "/etc/systemd/system/{{ item }}" - mode: 0644 - with_items: - - snowflake-proxy.service - -- name: Enable service snowflake-proxy - ansible.builtin.systemd: - name: snowflake-proxy - enabled: yes - -- name: Just force systemd to reread configs - ansible.builtin.systemd: - daemon_reload: yes - -- name: Start/restart service snowflake - ansible.builtin.service: - name: snowflake-proxy - state: restarted diff --git a/templates/snowflake-proxy.service.j2 b/templates/snowflake-proxy.service.j2 index a0fc8b9..9051dc2 100644 --- a/templates/snowflake-proxy.service.j2 +++ b/templates/snowflake-proxy.service.j2 @@ -26,6 +26,8 @@ CapabilityBoundingSet= ProtectProc=invisible PrivateUsers=true ProtectHostname=true +Restart=on-failure +RestartSec=5s [Install] WantedBy=multi-user.target