From 49620e25af2d7810659201ea6d4551b8d8a16af1 Mon Sep 17 00:00:00 2001 From: Zufar Dhiyaullhaq Date: Sun, 30 Jun 2024 11:24:36 +0700 Subject: [PATCH] feat: add frp server ansible Signed-off-by: Zufar Dhiyaullhaq --- README.md | 2 + ansible/server/README.md | 38 +++++++++++++++ ansible/server/group_vars/all.yml | 9 ++++ ansible/server/hosts/hosts | 2 + ansible/server/main.yml | 5 ++ ansible/server/roles/rfps/handlers/main.yaml | 3 ++ ansible/server/roles/rfps/tasks/main.yaml | 48 +++++++++++++++++++ .../roles/rfps/templates/frps.service.j2 | 10 ++++ .../server/roles/rfps/templates/frps.toml.j2 | 8 ++++ charts/frp-operator/README.md.gotmpl | 2 + controllers/client_controller.go | 2 +- 11 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 ansible/server/README.md create mode 100644 ansible/server/group_vars/all.yml create mode 100644 ansible/server/hosts/hosts create mode 100644 ansible/server/main.yml create mode 100644 ansible/server/roles/rfps/handlers/main.yaml create mode 100644 ansible/server/roles/rfps/tasks/main.yaml create mode 100644 ansible/server/roles/rfps/templates/frps.service.j2 create mode 100644 ansible/server/roles/rfps/templates/frps.toml.j2 diff --git a/README.md b/README.md index cfc2e74..e9f42d9 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,8 @@ token = yourtoken frps -c ./frps.ini ``` +You can reuse our build-in ansible playbook to setup the FRP server on your machine, please check https://github.com/zufardhiyaulhaq/frp-operator/tree/main/ansible/server + ## Usage 1. Apply some example ```console diff --git a/ansible/server/README.md b/ansible/server/README.md new file mode 100644 index 0000000..718951f --- /dev/null +++ b/ansible/server/README.md @@ -0,0 +1,38 @@ +# RFP Server Ansible + +This simple ansible to setup FRP server on the server that has public IP address and prerequisite of frp-operator on Kubernetes. + +### Setup Guide + +1. SSH to the VM and get admin access +```shell +sudo su +``` +2. clone the repository +```shell +git clone https://github.com/zufardhiyaulhaq/frp-operator +cd frp-operator/ansible/server +``` +3. Adjust variables +```shell +vi group_vars/all.yaml +``` +4. Install ansible +```shell +sudo apt-add-repository ppa:ansible/ansible -y +sudo apt update +sudo apt install ansible -y +``` +5. disable ansible hostkey checking +```shell +vi ~/.ansible.cfg + +[defaults] +host_key_checking = False +``` +6. Run ansible +``` +ansible-playbook main.yml -i hosts/hosts +``` + + diff --git a/ansible/server/group_vars/all.yml b/ansible/server/group_vars/all.yml new file mode 100644 index 0000000..b58954a --- /dev/null +++ b/ansible/server/group_vars/all.yml @@ -0,0 +1,9 @@ +version: 0.58.1 + +server_address: +server_port: +server_token: + +webserver_port: +webserver_user: +webserver_password: diff --git a/ansible/server/hosts/hosts b/ansible/server/hosts/hosts new file mode 100644 index 0000000..ce22aff --- /dev/null +++ b/ansible/server/hosts/hosts @@ -0,0 +1,2 @@ +[frps] +127.0.0.1 \ No newline at end of file diff --git a/ansible/server/main.yml b/ansible/server/main.yml new file mode 100644 index 0000000..47930c9 --- /dev/null +++ b/ansible/server/main.yml @@ -0,0 +1,5 @@ +- name: setup FRP Server + become: yes + hosts: frps + roles: + - frps \ No newline at end of file diff --git a/ansible/server/roles/rfps/handlers/main.yaml b/ansible/server/roles/rfps/handlers/main.yaml new file mode 100644 index 0000000..f430f9c --- /dev/null +++ b/ansible/server/roles/rfps/handlers/main.yaml @@ -0,0 +1,3 @@ +--- +- name: Reload systemd + ansible.builtin.command: systemctl daemon-reload \ No newline at end of file diff --git a/ansible/server/roles/rfps/tasks/main.yaml b/ansible/server/roles/rfps/tasks/main.yaml new file mode 100644 index 0000000..cbc9fa5 --- /dev/null +++ b/ansible/server/roles/rfps/tasks/main.yaml @@ -0,0 +1,48 @@ +--- + - name: Download FRP tarball + ansible.builtin.get_url: + url: https://github.com/fatedier/frp/releases/download/v{{ version }}/frp_{{ version }}_linux_amd64.tar.gz + dest: /tmp/frp_{{ version }}_linux_amd64.tar.gz + mode: '0644' + + - name: Extract FRP tarball + ansible.builtin.unarchive: + src: /tmp/frp_{{ version }}_linux_amd64.tar.gz + dest: /opt/ + remote_src: yes + creates: /opt/frp_{{ version }}_linux_amd64 + + - name: Copy frps to /usr/local/bin + ansible.builtin.copy: + src: /opt/frp_{{ version }}_linux_amd64/frps + dest: /usr/local/bin/frps + mode: '0755' + remote_src: yes + + - name: Ensure frp server directory exists + ansible.builtin.file: + path: /etc/frp + state: directory + + - name: Setup FRP server config for frps + ansible.builtin.template: + src: frps.toml.j2 + dest: /etc/frp/frps.toml + notify: Reload systemd + + - name: Ensure systemd service directory exists + ansible.builtin.file: + path: /etc/systemd/system + state: directory + + - name: Setup FRP systemd service for frps + ansible.builtin.template: + src: frps.service.j2 + dest: /etc/systemd/system/frps.service + notify: Reload systemd + + - name: Enable and start FRP service + ansible.builtin.systemd: + name: frps + enabled: yes + state: started \ No newline at end of file diff --git a/ansible/server/roles/rfps/templates/frps.service.j2 b/ansible/server/roles/rfps/templates/frps.service.j2 new file mode 100644 index 0000000..c105ad4 --- /dev/null +++ b/ansible/server/roles/rfps/templates/frps.service.j2 @@ -0,0 +1,10 @@ +[Unit] +Description=FRP Server +After=network.target + +[Service] +Type=simple +ExecStart=/usr/local/bin/frps -c /etc/frp/frps.toml + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/ansible/server/roles/rfps/templates/frps.toml.j2 b/ansible/server/roles/rfps/templates/frps.toml.j2 new file mode 100644 index 0000000..296602f --- /dev/null +++ b/ansible/server/roles/rfps/templates/frps.toml.j2 @@ -0,0 +1,8 @@ +serverAddr = "{{ server_address }}" +serverPort = {{ server_port }} +auth.method = "{{ server_token }}" + +webServer.addr = "{{ server_address }}" +webServer.port = {{ webserver_port }} +webServer.user = "{{ webserver_user }}" +webServer.password = "{{ webserver_password }}" \ No newline at end of file diff --git a/charts/frp-operator/README.md.gotmpl b/charts/frp-operator/README.md.gotmpl index 7fe3001..1f5f669 100644 --- a/charts/frp-operator/README.md.gotmpl +++ b/charts/frp-operator/README.md.gotmpl @@ -34,6 +34,8 @@ token = yourtoken frps -c ./frps.ini ``` +You can reuse our build-in ansible playbook to setup the FRP server on your machine, please check https://github.com/zufardhiyaulhaq/frp-operator/tree/main/ansible/server + ## Usage 1. Apply some example ```console diff --git a/controllers/client_controller.go b/controllers/client_controller.go index 477f220..ab4b818 100644 --- a/controllers/client_controller.go +++ b/controllers/client_controller.go @@ -151,7 +151,7 @@ func (r *ClientReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr pod, err := builder.NewPodBuilder(). SetName(client.Name). SetNamespace(client.Namespace). - SetImage("fatedier/frpc:v0.56.0"). + SetImage("fatedier/frpc:v0.58.1"). Build() if err != nil { return ctrl.Result{}, err