Skip to content

Commit 915c4dd

Browse files
committed
added role to install playbooks for ansible-init
1 parent 321fdb4 commit 915c4dd

File tree

7 files changed

+71
-4
lines changed

7 files changed

+71
-4
lines changed

ansible/bootstrap.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
environment:
2222
INSTALL_K3S_VERSION: "v1.31.0+k3s1"
2323
INSTALL_K3S_EXEC: "server"
24-
INSTALL_K3S_SKIP_START: true
24+
INSTALL_K3S_SKIP_START: "true"
25+
INSTALL_K3S_SKIP_ENABLE: "true"
2526
changed_when: true
2627

2728
- hosts: k3s_agent
@@ -33,7 +34,8 @@
3334
environment:
3435
INSTALL_K3S_VERSION: "v1.31.0+k3s1"
3536
INSTALL_K3S_EXEC: "agent"
36-
INSTALL_K3S_SKIP_START: true
37+
INSTALL_K3S_SKIP_START: "true"
38+
INSTALL_K3S_SKIP_ENABLE: "true"
3739
changed_when: true
3840

3941
- hosts: k3s
@@ -54,6 +56,11 @@
5456
- k3s
5557
- kubectl
5658

59+
- hosts: k3s
60+
become: yes
61+
tasks:
62+
- include_role:
63+
name: k3s
5764

5865
- hosts: cluster
5966
gather_facts: false
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
- hosts: localhost
2+
become: true
3+
vars:
4+
os_metadata: "{{ lookup('url', 'http://169.254.169.254/openstack/latest/meta_data.json') | from_json }}"
5+
k3s_token: "{{ os_metadata.meta.k3s_token }}"
6+
k3s_server_name: "{{ os_metadata.meta.k3s_server }}"
7+
tasks:
8+
- name: Add the token for joining the cluster to the environment
9+
no_log: true # avoid logging the server token
10+
ansible.builtin.lineinfile:
11+
path: "/etc/systemd/system/k3s-agent.service.env"
12+
line: "{{ item }}"
13+
with_items:
14+
- "K3S_TOKEN={{ k3s_token }}"
15+
- "K3S_URL=https://{{ k3s_server_name }}:6443"
16+
- name: Start k3s service
17+
ansible.builtin.systemd:
18+
name: k3s-agent
19+
daemon_reload: true
20+
state: started
21+
enabled: true
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
- hosts: localhost
2+
become: true
3+
vars:
4+
os_metadata: "{{ lookup('url', 'http://169.254.169.254/openstack/latest/meta_data.json') | from_json }}"
5+
k3s_token: "{{ os_metadata.meta.k3s_token }}"
6+
tasks:
7+
- name: Add the token for joining the cluster to the environment
8+
no_log: true # avoid logging the server token
9+
ansible.builtin.lineinfile:
10+
path: "/etc/systemd/system/k3s.service.env"
11+
line: "{{ item }}"
12+
with_items:
13+
- "K3S_TOKEN={{ k3s_token }}"
14+
- name: Start k3s service
15+
ansible.builtin.systemd:
16+
name: k3s
17+
daemon_reload: true
18+
state: started
19+
enabled: true

ansible/roles/k3s/tasks/main.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
3+
- name: Create ansible-init playbook install directory
4+
file:
5+
path: "/etc/ansible-init/playbooks"
6+
state: directory
7+
8+
- name: Install k3s server ansible-init playbook
9+
copy:
10+
src: start_k3s_server.yml
11+
dest: /etc/ansible-init/playbooks/0-start-k3s.yml
12+
when: inventory_hostname in groups["k3s_server"]
13+
14+
- name: Install k3s agent ansible-init playbook
15+
copy:
16+
src: start_k3s_agent.yml
17+
dest: /etc/ansible-init/playbooks/0-start-k3s.yml
18+
when: inventory_hostname in groups["k3s_agent"]

environments/common/inventory/groups

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ freeipa_client
136136
[ansible_init]
137137
# Hosts to run linux-anisble-init
138138

139-
[k3s_server]
139+
[k3s_server:children]
140140
# Host to run k3s server
141141
control
142142

143-
[k3s_agent]
143+
[k3s_agent:children]
144144
# Hosts to run as k3s agents
145145
login
146146
compute

environments/skeleton/{{cookiecutter.environment}}/terraform/compute/nodes.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ resource "openstack_compute_instance_v2" "compute" {
4747
metadata = {
4848
environment_root = var.environment_root
4949
k3s_token = var.k3s_token
50+
k3s_server = "${var.cluster_name}-control"
5051
}
5152

5253
user_data = <<-EOF

environments/skeleton/{{cookiecutter.environment}}/terraform/nodes.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ resource "openstack_compute_instance_v2" "login" {
126126
metadata = {
127127
environment_root = var.environment_root
128128
k3s_token = var.k3s_token
129+
k3s_server = "${var.cluster_name}-control"
129130
}
130131

131132
user_data = <<-EOF

0 commit comments

Comments
 (0)