Skip to content

Commit

Permalink
Update ansible roles
Browse files Browse the repository at this point in the history
- Add ansible role to provision the kubetail command line tool
  • Loading branch information
theodore86 committed Apr 14, 2023
1 parent a407dff commit bdc8de3
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![CircleCI](https://circleci.com/gh/theodore86/vagrantenv/tree/main.svg?style=svg&circle-token=bc7666e0b5736f67b6a4fdda6f244782d2062375)](https://circleci.com/gh/theodore86/vagrantenv/tree/main)
[![CircleCI](https://circleci.com/gh/theodore86/vagrantenv/tree/main.svg?style=shield)](https://circleci.com/gh/theodore86/vagrantenv/tree/main)
[![Sandbox](https://github.com/theodore86/vagrantenv/actions/workflows/provision.yml/badge.svg)](https://github.com/theodore86/vagrantenv/actions/workflows/provision.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Expand Down Expand Up @@ -83,6 +83,7 @@ Based on Ubuntu `jammy/22.04` box from: [HashiCorp's Vagrant Cloud](https://app.
- kubeps1
- kubecolor
- kubeshark
- kubetail

### Network Protocol Analyzers

Expand Down
1 change: 1 addition & 0 deletions docs/vagrant/provisioners.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ Supported options are:
- [kubeps1](https://github.com/jonmosco/kube-ps1) - Kubernetes prompt for bash and zsh.
- [kubecolor](https://github.com/hidetatz/kubecolor) - Colorize your kubectl output.
- [kubeshark](https://kubeshark.co/pcap-or-it-didnt-happen) - API Traffic Viewer for Kubernetes.
- [kubetail](https://github.com/johanhaleby/kubetail) - Bash script that enables you to aggregate (tail/follow) logs from multiple pods into one stream.
- [fzf](https://github.com/junegunn/fzf) - Command line fuzzy finder.
- [yq](https://github.com/mikefarah/yq) - A lightweight and portable command-line YAML, JSON and XML processor.
- [terragrunt](https://terragrunt.gruntwork.io/) - A thin wrapper around terraform (*orchestrator for terraform modules*).
Expand Down
1 change: 1 addition & 0 deletions provisioners/ansible/extra_vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ kubectx_version: 0.9.4
kubefwd_version: 1.22.4
kubeps1_version: 0.8.0
kubeshark_version: 38.3
kubetail_version: 1.6.17
tf_version: 1.3.6
tgrunt_version: 0.40.0
vagrant_version: 2.3.4
Expand Down
1 change: 1 addition & 0 deletions provisioners/ansible/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- { role: 'kubernetes/kubeps1', tags: 'kubeps1' }
- { role: 'kubernetes/kubecolor', tags: 'kubecolor' }
- { role: 'kubernetes/kubeshark', tags: 'kubeshark' }
- { role: 'kubernetes/kubetail', tags: 'kubetail' }
- { role: 'hashicorp/vagrant', tags: 'vagrant' }
- { role: 'hashicorp/terraform', tags: 'terraform' }
- { role: 'hashicorp/vault', tags: 'hvault' }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
kubetail_version: '1.6.17'
kubetail_install_dir: '/usr/local/bin'
...
15 changes: 15 additions & 0 deletions provisioners/ansible/roles/kubernetes/kubetail/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- name: 'Check installed kubetail version'
shell: '{{ kubetail_install_dir }}/kubetail --version 2>/dev/null'
args:
executable: '/bin/bash'
changed_when: false
register: 'kubetail_installed_version'

- name: 'Verify installed kubetail version'
assert:
that:
- 'kubetail_version == kubetail_installed_version.stdout'
fail_msg: 'kubetail installation failed, {{ kubetail_version }} != {{ kubetail_installed_version.stdout }}'
success_msg: 'Installed kubetail version is: {{ kubetail_version }}'
...
80 changes: 80 additions & 0 deletions provisioners/ansible/roles/kubernetes/kubetail/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
- name: 'Check if is already installed'
stat:
path: '{{ kubetail_install_dir }}/kubetail'
register: 'kubetail_check_existing'

- name: 'Check existing version'
shell: "{{ kubetail_install_dir }}/kubetail --version 2>/dev/null"
args:
executable: '/bin/bash'
failed_when: false
changed_when: false
register: 'kubetail_existing_version'
when: 'kubetail_check_existing.stat.exists'

- name: 'Ensure installation directory exists'
file:
path: '{{ kubetail_install_dir }}'
state: 'directory'
mode: 0755
owner: 'root'
group: 'root'
become: 'yes'

- name: 'Remove current installed version'
file:
path: '{{ kubetail_install_dir }}/kubetail'
state: 'absent'
become: 'yes'
when:
- 'kubetail_check_existing.stat.exists'
- 'kubetail_existing_version.stdout != kubetail_version'

- name: 'Unarchive zip folder'
unarchive:
src: '{{ kubetail_download_url }}'
dest: '/tmp'
mode: 0755
remote_src: 'yes'
become: 'yes'
when: >
not kubetail_check_existing.stat.exists
or kubetail_existing_version.stdout != kubetail_version
- name: 'Copy script to installation directory'
copy:
src: '/tmp/kubetail-{{ kubetail_version }}/kubetail'
dest: '{{ kubetail_install_dir }}/kubetail'
owner: 'root'
group: 'root'
mode: 0755
become: 'yes'
when: >
not kubetail_check_existing.stat.exists
or kubetail_existing_version.stdout != kubetail_version
notify:
- 'Check installed kubetail version'
- 'Verify installed kubetail version'

- name: 'Remove bash completion script'
file:
path: '/etc/profile.d/kubetail.sh'
state: 'absent'
become: 'yes'
when:
- 'kubetail_check_existing.stat.exists'
- 'kubetail_existing_version.stdout != kubetail_version'

- name: 'Enable bash completion'
copy:
src: '/tmp/kubetail-{{ kubetail_version }}/completion/kubetail.bash'
dest: '/etc/profile.d/kubetail.sh'
owner: 'root'
group: 'root'
mode: 0644
become: 'yes'
when: >
not kubetail_check_existing.stat.exists
or kubetail_existing_version.stdout != kubetail_version
...
4 changes: 4 additions & 0 deletions provisioners/ansible/roles/kubernetes/kubetail/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
kubetail_zip_folder: '{{ kubetail_version }}.zip'
kubetail_download_url: 'https://github.com/johanhaleby/kubetail/archive/refs/tags/{{ kubetail_zip_folder }}'
...
1 change: 1 addition & 0 deletions vagrant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
- "kubectl"
- "kubectx"
- "kubefwd"
- "kubetail"
- "helm"
- "helm_dash"
- "kind"
Expand Down

0 comments on commit bdc8de3

Please sign in to comment.