From 1f9947ca8d954e94949dad1ae4c9e67b9cdbee97 Mon Sep 17 00:00:00 2001 From: Ibrahim Mkusa Date: Sat, 16 Nov 2024 13:10:31 -0500 Subject: [PATCH] snapy playbook to install kubernetes repo and tools --- inventory/inventory | 4 +++- playbooks/hashicorp/install.yml | 2 +- playbooks/k8s/install_kubectl.yml | 38 +++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 playbooks/k8s/install_kubectl.yml diff --git a/inventory/inventory b/inventory/inventory index 65831ff..a042282 100644 --- a/inventory/inventory +++ b/inventory/inventory @@ -5,13 +5,15 @@ localhost 192.168.2.236 [docker] -node1 ansible_user=ansible +docker0 ansible_user=ansible [aws] aws ansible_user=ubuntu [helm] node1 ansible_user=ansible +node4 ansible_user=ansible + [terraform] node1 diff --git a/playbooks/hashicorp/install.yml b/playbooks/hashicorp/install.yml index 8f7cec5..2bb701e 100644 --- a/playbooks/hashicorp/install.yml +++ b/playbooks/hashicorp/install.yml @@ -1,6 +1,6 @@ --- - name: install terraform on deb/rpm family - hosts: terraform + hosts: localhost become: yes tasks: - name: update cache on debian/rpm family diff --git a/playbooks/k8s/install_kubectl.yml b/playbooks/k8s/install_kubectl.yml new file mode 100644 index 0000000..6f34cb2 --- /dev/null +++ b/playbooks/k8s/install_kubectl.yml @@ -0,0 +1,38 @@ +--- +- name: adds the kubernetes repo and installs kubectl + hosts: localhost + become: true + tasks: + - name: update apt cache + ansible.builtin.apt: + update_cache: true + + - name: install core pre-reqs + ansible.builtin.apt: + pkg: + - apt-transport-https + - ca-certificates + - curl + - gnupg + + - name: check to see if gpg key exists + ansible.builtin.stat: + path: /etc/apt/keyrings/kubernetes-apt-keyring.gpg + register: st + + - name: download the key and install it + ansible.builtin.shell: | + curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.31/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg + sudo chmod 644 /etc/apt/keyrings/kubernetes-apt-keyring.gpg # allow unprivileged APT programs to read this keyring + when: st.stat.exists != true + + - name: add the kubernetes apt repository + ansible.builtin.apt_repository: + repo: "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.31/deb/ /" + state: present + filename: kubernetes.list + + - name: update apt cache and install kubectl + ansible.builtin.apt: + name: kubectl + update_cache: true