Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first draft add tailscale/headscale #49

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions mojaloop/iac/roles/headscale/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
headscale_fqdn: a.b.c
headscale_root_dir: /root/headscale-compose
headscale_image_version: 0.18.6
headscale_caddy_image_version: 2.6.2
headscale_acme_email: [email protected]
enable_oauth: false
headscale_oidc_issuer: https://gitlab.com
headscale_oidc_client_id: clientid
headscale_oidc_client_secret: crazysecret
5 changes: 5 additions & 0 deletions mojaloop/iac/roles/headscale/handlers/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- name: Restart Headscale
systemd:
name: "headscale"
state: restarted
daemon_reload: true
84 changes: 84 additions & 0 deletions mojaloop/iac/roles/headscale/tasks/configure.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
- name: Wait netmaker api server to respond
uri:
url: https://api.{{ netmaker_base_domain }}/api/networks
method: GET
headers:
Authorization: Bearer {{ netmaker_master_key }}
register: _result
until: _result.status == 200
retries: 30
delay: 10 # Every 10 seconds

- name: Add admin user
uri:
url: https://api.{{ netmaker_base_domain }}/api/users/{{ netmaker_admin_username }}
method: POST
headers:
Content-Type: application/json
Authorization: Bearer {{ netmaker_master_key }}
body: "{{ lookup('template', 'createadminuser.json.j2') }}"
body_format: json
status_code: [200, 400]

- name: Add networks if don't exist
uri:
url: https://api.{{ netmaker_base_domain }}/api/networks
method: POST
headers:
Content-Type: application/json
Authorization: Bearer {{ netmaker_master_key }}
body: "{{ lookup('template', 'createnetwork.json.j2') }}"
body_format: json
status_code: [200, 400]
loop: "{{ netmaker_networks }}"
loop_control:
index_var: ipindex

- name: Get keys
uri:
url: https://api.{{ netmaker_base_domain }}/api/v1/enrollment-keys
method: GET
headers:
Content-Type: application/json
Authorization: Bearer {{ netmaker_master_key }}
status_code: [200]
return_content: true
register: key_response

- name: Add key for control network for netclient
uri:
url: https://api.{{ netmaker_base_domain }}/api/v1/enrollment-keys
method: POST
headers:
Content-Type: application/json
Authorization: Bearer {{ netmaker_master_key }}
body: "{{ lookup('template', 'createkey.json.j2') }}"
body_format: json
status_code: [200, 400]
vars:
keytag: "{{ item.0.network_name }}-{{ item.1 }}"
when: "keytag not in key_response.content"
loop: "{{ netmaker_networks | subelements('node_keys') }}"

- name: Get keys again
uri:
url: https://api.{{ netmaker_base_domain }}/api/v1/enrollment-keys
method: GET
headers:
Content-Type: application/json
Authorization: Bearer {{ netmaker_master_key }}
status_code: [200]
return_content: true
register: key_response2

- name: copy keys
copy:
content: "{{ key_response2.content }}"
dest: "{{ netmaker_enrollment_key_list_file_location }}"
delegate_to: localhost

# - name: Save access token for bastion netclient
# vars:
# query: "[?tags[0]=='{{ netmaker_control_network_name }}-access'].token"
# set_fact:
# netmaker_control_network_access_string: "{{ key_response2.json | json_query(query) | first }}"
38 changes: 38 additions & 0 deletions mojaloop/iac/roles/headscale/tasks/install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
- name: Update apt cache
shell: apt update

- name: Install dependencies
package:
name:
- wireguard

- name: "create directory for project"
file:
path: "{{ headscale_root_dir }}/conf"
state: directory
recurse: yes

- name: "deploy systemd service"
template:
src: "../templates/headscale.service.j2"
dest: "/etc/systemd/system/headscale.service"
notify: Restart Headscale

- name: "deploy headscale compose file"
template:
src: "../templates/headscale.docker-compose.yaml.j2"
dest: "{{ headscale_root_dir}}/headscale-docker-compose.yaml"
notify: Restart Headscale

- name: "deploy headscale config file"
template:
src: "../templates/headscale.config.yaml.j2"
dest: "{{ headscale_root_dir}}/conf/config.yaml"
notify: Restart Headscale

- name: "set headscale to auto restart"
systemd:
enabled: true
daemon_reload: true
name: "headscale"
state: started
2 changes: 2 additions & 0 deletions mojaloop/iac/roles/headscale/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- include_tasks: install.yaml
- include_tasks: configure.yaml
Loading