Skip to content

Commit

Permalink
feat: add frp server ansible
Browse files Browse the repository at this point in the history
Signed-off-by: Zufar Dhiyaullhaq <[email protected]>
  • Loading branch information
zufardhiyaulhaq committed Jun 30, 2024
1 parent ff910a6 commit 49620e2
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions ansible/server/README.md
Original file line number Diff line number Diff line change
@@ -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
```


9 changes: 9 additions & 0 deletions ansible/server/group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 0.58.1

server_address:
server_port:
server_token:

webserver_port:
webserver_user:
webserver_password:
2 changes: 2 additions & 0 deletions ansible/server/hosts/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[frps]
127.0.0.1
5 changes: 5 additions & 0 deletions ansible/server/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- name: setup FRP Server
become: yes
hosts: frps
roles:
- frps
3 changes: 3 additions & 0 deletions ansible/server/roles/rfps/handlers/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: Reload systemd
ansible.builtin.command: systemctl daemon-reload
48 changes: 48 additions & 0 deletions ansible/server/roles/rfps/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions ansible/server/roles/rfps/templates/frps.service.j2
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions ansible/server/roles/rfps/templates/frps.toml.j2
Original file line number Diff line number Diff line change
@@ -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 }}"
2 changes: 2 additions & 0 deletions charts/frp-operator/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion controllers/client_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 49620e2

Please sign in to comment.