forked from kubealex/libvirt-k8s-provisioner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
02_prepare_setup.yml
111 lines (94 loc) · 3.8 KB
/
02_prepare_setup.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
- name: This play ensures environment is set up for cluster creation
hosts: vm_host
vars_files:
- vars/k8s_cluster.yml
tasks:
- name: Set user home as fact
ansible.builtin.set_fact:
home_dir: "{{ ansible_env.HOME }}"
- name: Ensure needed pip packages are present
ansible.builtin.pip:
executable: pip3
name: "{{ item }}"
loop: "{{ python_packages }}"
- name: Ensure workspace directory exists
ansible.builtin.file:
path: "{{ workspace_directory.base_path }}"
state: directory
mode: "0755"
- name: Ensure cluster folder exists
ansible.builtin.file:
path: "{{ workspace_directory.base_path }}/clusters/{{ k8s.cluster_name | default('k8s-test', true) }}"
state: directory
mode: "0755"
- name: Ensure pivot tmp folder exists
ansible.builtin.file:
path: "/tmp/{{ k8s.cluster_name | default('k8s-test', true) }}"
state: directory
mode: "0755"
- name: Populate cluster folder with terraform files
ansible.builtin.copy:
src: "files/terraform/"
dest: "{{ workspace_directory.base_path }}/clusters/{{ k8s.cluster_name | default('k8s-test', true) }}"
mode: "0755"
- name: Snapshot cluster configuration for further use
ansible.builtin.copy:
src: "vars"
dest: "{{ workspace_directory.base_path }}/clusters/{{ k8s.cluster_name | default('k8s-test', true) }}/"
mode: "0755"
- name: Ensure helm is installed
ansible.builtin.unarchive:
src: "{{ helm.helm_installer }}"
dest: /tmp/
remote_src: true
- name: Install helm in PATH
ansible.builtin.copy:
src: /tmp/linux-amd64/helm
dest: /usr/bin/
remote_src: true
mode: +x
become: true
- name: Install Helm Diff
kubernetes.core.helm_plugin:
state: present
plugin_path: https://github.com/databus23/helm-diff
- name: Remove directory
ansible.builtin.file:
path: /tmp/linux-amd64
state: absent
- name: Create ssh keypair
community.crypto.openssh_keypair:
path: "{{ playbook_dir }}/id_rsa_{{ k8s.cluster_name | default('k8s-test', true) }}"
delegate_to: localhost
- name: Copy SSH keys in working directory
ansible.builtin.copy:
src: "{{ playbook_dir }}/{{ item }}"
dest: "{{ workspace_directory.base_path }}/clusters/{{ k8s.cluster_name | default('k8s-test', true) }}/{{ item }}"
mode: "0755"
loop:
- id_rsa_{{ k8s.cluster_name | default('k8s-test', true) }}
- id_rsa_{{ k8s.cluster_name | default('k8s-test', true) }}.pub
- name: Getting ssh private key
ansible.builtin.slurp:
src: "{{ workspace_directory.base_path }}/clusters/{{ k8s.cluster_name | default('k8s-test', true) }}/id_rsa_{{ k8s.cluster_name | default('k8s-test', true) }}" # noqa yaml[line-length]
register: k8s_key
- name: Getting ssh public key
ansible.builtin.slurp:
src: "{{ workspace_directory.base_path }}/clusters/{{ k8s.cluster_name | default('k8s-test', true) }}/id_rsa_{{ k8s.cluster_name | default('k8s-test', true) }}.pub" # noqa yaml[line-length]
register: k8s_key_pub
- name: Set SSH keys as fact
ansible.builtin.set_fact:
k8s_key: "{{ k8s_key['content'] | b64decode }}"
k8s_key_pub: "{{ k8s_key_pub['content'] | b64decode }}"
- name: Download CentOS image
ansible.builtin.get_url:
url: "{{ centos.cloud_image }}"
dest: /tmp/{{ image_name }}.qcow2
mode: "0777"
when: k8s.cluster_os == 'CentOS'
- name: Download Ubuntu image
ansible.builtin.get_url:
url: "{{ ubuntu_jammy.cloud_image }}"
dest: /tmp/{{ image_name }}.qcow2
mode: "0777"
when: k8s.cluster_os == 'Ubuntu'