|
| 1 | +--- |
| 2 | +- name: Set download_file_name |
| 3 | + set_fact: |
| 4 | + download_file_name: "frp_{{ frp_config.frp_version }}_{{ frp_config.frp_os }}_{{ frp_config.frp_arch }}" |
| 5 | + |
| 6 | +- name: Create remote access directory |
| 7 | + file: |
| 8 | + path: "{{ frp_config.remote_access_dir }}" |
| 9 | + state: directory |
| 10 | + mode: '0755' |
| 11 | + become: yes |
| 12 | + |
| 13 | +- name: Download FRP release |
| 14 | + get_url: |
| 15 | + url: "https://github.com/fatedier/frp/releases/download/v{{ frp_config.frp_version }}/{{ download_file_name }}.tar.gz" |
| 16 | + dest: "/tmp/{{ download_file_name }}.tar.gz" |
| 17 | + mode: '0644' |
| 18 | + become: yes |
| 19 | + |
| 20 | +- name: Extract FRP archive |
| 21 | + unarchive: |
| 22 | + src: "/tmp/{{ download_file_name }}.tar.gz" |
| 23 | + dest: /tmp/ |
| 24 | + remote_src: yes |
| 25 | + become: yes |
| 26 | + |
| 27 | +- name: Stop FRP service before copying new binary |
| 28 | + systemd: |
| 29 | + name: "{{ frp_config.frp_component }}" |
| 30 | + state: stopped |
| 31 | + ignore_errors: yes |
| 32 | + become: yes |
| 33 | + |
| 34 | +- name: Copy FRP binary |
| 35 | + copy: |
| 36 | + src: "/tmp/{{ download_file_name }}/{{ frp_config.frp_component }}" |
| 37 | + dest: "{{ frp_config.remote_access_dir }}/{{ frp_config.frp_component }}" |
| 38 | + remote_src: yes |
| 39 | + mode: '0755' |
| 40 | + become: yes |
| 41 | + |
| 42 | +- name: Set capability on FRP binary to bind to privileged ports |
| 43 | + capabilities: |
| 44 | + path: "{{ frp_config.remote_access_dir }}/{{ frp_config.frp_component }}" |
| 45 | + capability: cap_net_bind_service=+ep |
| 46 | + state: present |
| 47 | + become: yes |
| 48 | + |
| 49 | +# Get the FRP token from environment variable |
| 50 | +- name: Get FRP token from environment variable |
| 51 | + set_fact: |
| 52 | + frp_token: "{{ lookup('env', 'FRP_TOKEN') }}" |
| 53 | + |
| 54 | +- name: Copy FRP config |
| 55 | + template: |
| 56 | + src: "{{ playbook_dir }}/../frp_config/{{ frp_config.frp_component }}.toml" |
| 57 | + dest: "{{ frp_config.remote_access_dir }}/{{ frp_config.frp_component }}.toml" |
| 58 | + mode: '0644' |
| 59 | + vars: |
| 60 | + token: "{{ frp_token }}" |
| 61 | + become: yes |
| 62 | + |
| 63 | +- name: Copy systemd service file |
| 64 | + copy: |
| 65 | + src: "{{ playbook_dir }}/../frp_config/{{ frp_config.frp_component }}.service" |
| 66 | + dest: "/etc/systemd/system/{{ frp_config.frp_component }}.service" |
| 67 | + mode: '0644' |
| 68 | + become: yes |
| 69 | + |
| 70 | +- name: Reload systemd |
| 71 | + systemd: |
| 72 | + daemon_reload: yes |
| 73 | + become: yes |
| 74 | + |
| 75 | +- name: Start and enable FRP service |
| 76 | + systemd: |
| 77 | + name: "{{ frp_config.frp_component }}" |
| 78 | + state: started |
| 79 | + enabled: yes |
| 80 | + become: yes |
| 81 | + |
| 82 | +- name: Check FRP service status |
| 83 | + command: systemctl status {{ frp_config.frp_component }} |
| 84 | + register: service_status |
| 85 | + changed_when: false |
| 86 | + become: yes |
| 87 | + |
| 88 | +- name: Display FRP service status |
| 89 | + debug: |
| 90 | + var: service_status.stdout_lines |
| 91 | + |
| 92 | +- name: Wait for 5 seconds |
| 93 | + pause: |
| 94 | + seconds: 5 |
| 95 | + |
| 96 | +- name: Check FRP service status again |
| 97 | + command: systemctl status {{ frp_config.frp_component }} |
| 98 | + register: service_status_after |
| 99 | + changed_when: false |
| 100 | + become: yes |
| 101 | + |
| 102 | +- name: Display FRP service status after pause |
| 103 | + debug: |
| 104 | + var: service_status_after.stdout_lines |
| 105 | + |
| 106 | +- name: Cleanup downloaded files |
| 107 | + file: |
| 108 | + path: "{{ item }}" |
| 109 | + state: absent |
| 110 | + with_items: |
| 111 | + - "/tmp/{{ download_file_name }}.tar.gz" |
| 112 | + - "/tmp/{{ download_file_name }}" |
| 113 | + become: yes |
0 commit comments