feat: move kubeconfig to provision folder during ansible k3s-install (#91)

* feat: move kubeconfig to provision folder during ansible k3s-install

Signed-off-by: Devin Buhl <devin.kray@gmail.com>

* fix: update kubeconfig refereces

Signed-off-by: Devin Buhl <devin.kray@gmail.com>
This commit is contained in:
Devin Buhl authored and GitHub committed 2021-09-30 14:52:00 -04:00
1 parent 925a541ae0
commit 7f406b8d39
4 files changed
+14 -9

No files matched your search

+1 -1
View File
@@ -1,4 +1,4 @@
#shellcheck disable=SC2148,SC2155 #shellcheck disable=SC2148,SC2155
export KUBECONFIG=$(expand_path ./kubeconfig) export KUBECONFIG=$(expand_path ./provision/kubeconfig)
export ANSIBLE_CONFIG=$(expand_path ./ansible.cfg) export ANSIBLE_CONFIG=$(expand_path ./ansible.cfg)
export GPG_TTY=$(tty) export GPG_TTY=$(tty)
+2 -4
View File
@@ -207,7 +207,7 @@ In order to use Terraform and `cert-manager` with the Cloudflare DNS challenge y
### :sailboat:&nbsp; Installing k3s with Ansible ### :sailboat:&nbsp; Installing k3s with Ansible
:round_pushpin: Here we will be running a Ansible Playbook to install [k3s](https://k3s.io/) with [this](https://galaxy.ansible.com/xanmanning/k3s) wonderful k3s Ansible galaxy role. After completion, Ansible will drop a `kubeconfig` in `/tmp/kubeconfig` for use with interacting with your cluster with `kubectl`. This file should be manually copied to the root of your repository. :round_pushpin: Here we will be running a Ansible Playbook to install [k3s](https://k3s.io/) with [this](https://galaxy.ansible.com/xanmanning/k3s) wonderful k3s Ansible galaxy role. After completion, Ansible will drop a `kubeconfig` in `./provision/kubeconfig` for use with interacting with your cluster with `kubectl`.
1. Verify Ansible can view your config by running `task ansible:list` 1. Verify Ansible can view your config by running `task ansible:list`
@@ -217,9 +217,7 @@ In order to use Terraform and `cert-manager` with the Cloudflare DNS challenge y
4. If everything goes as planned you should see Ansible running the k3s install Playbook against your nodes. 4. If everything goes as planned you should see Ansible running the k3s install Playbook against your nodes.
5. Copy the `kubeconfig` file from `/tmp` to your repository. 5. Verify the nodes are online
6. Verify the nodes are online
```sh ```sh
kubectl --kubeconfig=./provision/kubeconfig get nodes kubectl --kubeconfig=./provision/kubeconfig get nodes
+1 -1
View File
@@ -9,7 +9,7 @@ vars:
TERRAFORM_DIR: "{{.PROJECT_DIR}}/provision/terraform" TERRAFORM_DIR: "{{.PROJECT_DIR}}/provision/terraform"
env: env:
KUBECONFIG: "{{.PROJECT_DIR}}/kubeconfig" KUBECONFIG: "{{.PROJECT_DIR}}/provision/kubeconfig"
includes: includes:
ansible: .taskfiles/ansible.yml ansible: .taskfiles/ansible.yml
+10 -3
View File
@@ -27,11 +27,18 @@
name: xanmanning.k3s name: xanmanning.k3s
public: true public: true
- name: Copy kubeconfig locally to /tmp - name: Get absolute path to this Git repository
delegate_to: localhost
become: false
run_once: true
ansible.builtin.command: "git rev-parse --show-toplevel"
register: repo_abs_path
- name: Copy kubeconfig to provision folder
run_once: true run_once: true
ansible.builtin.fetch: ansible.builtin.fetch:
src: "/etc/rancher/k3s/k3s.yaml" src: "/etc/rancher/k3s/k3s.yaml"
dest: "/tmp/kubeconfig" dest: "{{ repo_abs_path.stdout }}/provision/kubeconfig"
flat: true flat: true
when: when:
- k3s_control_node is defined - k3s_control_node is defined
@@ -42,7 +49,7 @@
become: false become: false
run_once: true run_once: true
ansible.builtin.replace: ansible.builtin.replace:
path: "/tmp/kubeconfig" path: "{{ repo_abs_path.stdout }}/provision/kubeconfig"
regexp: "https://127.0.0.1:6443" regexp: "https://127.0.0.1:6443"
replace: "https://{{ k3s_registration_address }}:6443" replace: "https://{{ k3s_registration_address }}:6443"