Skip to content

Instantly share code, notes, and snippets.

@vandot
Last active November 4, 2020 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vandot/f22e313fd1dfe24eedd32d28f9f35727 to your computer and use it in GitHub Desktop.
Save vandot/f22e313fd1dfe24eedd32d28f9f35727 to your computer and use it in GitHub Desktop.
ansible-playbook k3sup_ha.yml
---
- hosts: localhost
gather_facts: true
connection: local
roles:
- role: vandot.k3sup.k3sup
tasks:
- name: Create ssh key
community.digitalocean.digital_ocean_sshkey:
oauth_token: "{{ oauth_token }}"
name: mykey
ssh_pub_key: "{{ lookup('file', '~/.ssh/id_ed25519.pub') }}"
state: present
register: ssh_key
- name: Create server
community.digitalocean.digital_ocean_droplet:
state: present
name: k3s-server
oauth_token: "{{ oauth_token }}"
size: 2gb
region: fra1
image: ubuntu-20-04-x64
wait_timeout: 500
ssh_keys:
- "{{ ssh_key.data.ssh_key.fingerprint }}"
tags:
- "server"
- "k3sup"
register: k3s_server
- name: Create server-2
community.digitalocean.digital_ocean_droplet:
state: present
name: k3s-server-2
oauth_token: "{{ oauth_token }}"
size: 2gb
region: fra1
image: ubuntu-20-04-x64
wait_timeout: 500
ssh_keys:
- "{{ ssh_key.data.ssh_key.fingerprint }}"
tags:
- "server"
- "k3sup"
register: k3s_server_2
- name: Create agents
community.digitalocean.digital_ocean_droplet:
state: present
name: "{{ item }}"
oauth_token: "{{ oauth_token }}"
size: 2gb
region: fra1
image: ubuntu-20-04-x64
wait_timeout: 500
ssh_keys:
- "{{ ssh_key.data.ssh_key.fingerprint }}"
tags:
- "agent"
- "k3sup"
register: k3s_agent
with_items:
- k3s-agent1
- k3s-agent2
- name: Install k3s server on k3s-server
vandot.k3sup.k3sup:
action: server
ip: "{{ k3s_server.data.ip_address }}"
ssh_key: "~/.ssh/id_ed25519"
cluster: true
k3s_channel: latest
- name: Install k3s server on k3s-server-2
vandot.k3sup.k3sup:
action: agent
ip: "{{ k3s_server_2.data.ip_address }}"
ssh_key: "~/.ssh/id_ed25519"
k3s_channel: latest
server: true
server_ip: "{{ k3s_server.data.ip_address }}"
- name: Install k3s agent on k3s-agents
vandot.k3sup.k3sup:
action: agent
ip: "{{ item.data.ip_address }}"
server_ip: "{{ k3s_server.data.ip_address }}"
ssh_key: "~/.ssh/id_ed25519"
k3s_channel: latest
with_items:
- "{{k3s_agent.results}}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment