From 56c3c28379630ce6280f170df06fdf2566371295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sp=C3=BChler=20Stefan?= Date: Wed, 28 Sep 2022 10:01:36 +0200 Subject: [PATCH 1/5] Move all tasks shared on all Linux distros to linux-common.yml --- tasks/arch.yml | 58 -------------------------------------- tasks/debian-bullseye.yml | 58 -------------------------------------- tasks/debian.yml | 59 --------------------------------------- tasks/fedora.yml | 59 --------------------------------------- tasks/linux-common.yml | 58 ++++++++++++++++++++++++++++++++++++++ tasks/main.yml | 14 ++++++---- tasks/ubuntu.yml | 58 -------------------------------------- 7 files changed, 67 insertions(+), 297 deletions(-) create mode 100644 tasks/linux-common.yml 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..e92e420 100644 --- a/tasks/debian-bullseye.yml +++ b/tasks/debian-bullseye.yml @@ -8,61 +8,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..855ce9a 100644 --- a/tasks/debian.yml +++ b/tasks/debian.yml @@ -14,62 +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/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..8ab6cab --- /dev/null +++ b/tasks/linux-common.yml @@ -0,0 +1,58 @@ +--- +- 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/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 From bfdea49661e007da6ffb7a79e64ff7b96337a5e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sp=C3=BChler=20Stefan?= Date: Wed, 28 Sep 2022 10:03:10 +0200 Subject: [PATCH 2/5] only restart snowflake daemon if there where changes --- handlers/main.yml | 4 ++++ tasks/linux-common.yml | 7 +++---- 2 files changed, 7 insertions(+), 4 deletions(-) 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/linux-common.yml b/tasks/linux-common.yml index 8ab6cab..9fb1dee 100644 --- a/tasks/linux-common.yml +++ b/tasks/linux-common.yml @@ -34,6 +34,7 @@ dest: /usr/bin/ mode: a+x remote_src: yes + notify: restart snowflake - name: Add unit systemd template: @@ -42,17 +43,15 @@ 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 -- name: Start/restart service snowflake - ansible.builtin.service: - name: snowflake-proxy - state: restarted From b0afa428c2d185931147035a73350f890d6302b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sp=C3=BChler=20Stefan?= Date: Wed, 28 Sep 2022 10:45:56 +0200 Subject: [PATCH 3/5] update apt cache on debian This fixes the error "The value 'buster-backports' is invalid for APT::Default-Release as such a release is not available in the sources" on systems where apt update was never run before. --- tasks/debian-bullseye.yml | 6 ++++++ tasks/debian.yml | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/tasks/debian-bullseye.yml b/tasks/debian-bullseye.yml index e92e420..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 }}" diff --git a/tasks/debian.yml b/tasks/debian.yml index 855ce9a..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" From f704ceaedc5170571b5313c8eceac96aa41db968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sp=C3=BChler=20Stefan?= Date: Wed, 28 Sep 2022 18:01:37 +0200 Subject: [PATCH 4/5] restart snowflake-proxy on failure --- templates/snowflake-proxy.service.j2 | 2 ++ 1 file changed, 2 insertions(+) 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 From 56419c77ab9f1826ea9c5c0ec88745df6a27a4d1 Mon Sep 17 00:00:00 2001 From: Bauruine Date: Mon, 14 Aug 2023 15:34:19 +0200 Subject: [PATCH 5/5] snowflake: remove deprecated warn option --- tasks/linux-common.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/tasks/linux-common.yml b/tasks/linux-common.yml index 9fb1dee..3e8823a 100644 --- a/tasks/linux-common.yml +++ b/tasks/linux-common.yml @@ -15,7 +15,6 @@ - name: go get command: go get args: - warn: no chdir: /home/{{ snowflake_user }}/repo/proxy register: go_get when: clone_git is changed @@ -23,7 +22,6 @@ - name: go build command: go build args: - warn: no chdir: /home/{{ snowflake_user }}/repo/proxy register: go_build when: clone_git is changed