Skip to content

Commit

Permalink
Add kube-ps1 ansible role
Browse files Browse the repository at this point in the history
- Add role for kube-ps1 kubernetes prompt
- Update project documentation
  • Loading branch information
theodore86 committed Sep 4, 2022
1 parent c13b874 commit 1d0c82d
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ Based on Ubuntu `focal/20.04` box from: [HashiCorp's Vagrant Cloud](https://app.
- k9s
- kubectx
- kubens
- kubeshell
- kubeps1

### Network Protocol Analyzers
- tshark
Expand Down
1 change: 1 addition & 0 deletions docs/vagrant/provisioners.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ Supported options are:
- [kubectx](https://github.com/ahmetb/kubectx) - Tool to switch between kubernetes contexts (clusters).
- [kubefwd](https://github.com/txn2/kubefwd) - Kubernetes port forwarding for local development.
- [kubeshell](https://github.com/cloudnativelabs/kube-shell) - An integrated shell for working with Kubernetes CLI.
- [kubeps1](https://github.com/jonmosco/kube-ps1) - Kubernetes prompt for bash and zsh.
- [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/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- { role: 'kubernetes/kubefwd', tags: 'kubefwd' }
- { role: 'kubernetes/kubectx', tags: 'kubectx' }
- { role: 'kubernetes/kubeshell', tags: 'kubeshell' }
- { role: 'kubernetes/kubeps1', tags: 'kubeps1' }
- { role: 'hashicorp/vagrant', tags: 'vagrant' }
- { role: 'hashicorp/terraform', tags: 'terraform' }
- { role: 'hashicorp/vault', tags: 'hvault' }
Expand Down
23 changes: 23 additions & 0 deletions provisioners/ansible/roles/kubernetes/kubeps1/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
kubeps1_version: '0.7.0'
kubeps1_install_dir: '/usr/local/bin'

# main settings
kubeps1_binary: 'kubectl'
kubeps1_ns_enabled: true
kubeps1_prefix: '('
kubeps1_symbol_enabled: true
kubeps1_symbol_padding: false
kubeps1_symbol_use_img: false
kubeps1_separator: '|'
kubeps1_divider: ':'
kubeps1_suffix: ')'

# color settings
kubeps1_prefix_color: 'null'
kubeps1_symbol_color: 'blue'
kubeps1_ctx_color: 'red'
kubeps1_suffix_color: 'null'
kubeps1_ns_color: 'cyan'
kubeps1_bg_color: 'null'
...
34 changes: 34 additions & 0 deletions provisioners/ansible/roles/kubernetes/kubeps1/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: 'Ensure checkout directory'
file:
path: '{{ k9s_checkout_dir }}'
state: 'directory'
mode: 0775

- name: 'Checkout repository'
git:
repo: '{{ kubeps1_repository }}'
dest: '{{ kubeps1_checkout_dir }}'
version: 'v{{ kubeps1_version }}'
accept_hostkey: 'yes'
update: 'no'
force: 'yes'
clone: 'yes'

- name: 'Copy script under source directory'
copy:
src: '{{ kubeps1_checkout_dir }}/kube-ps1.sh'
dest: '/etc/profile.d/kube-ps1.sh'
mode: 0644
remote_src: 'yes'
become: 'yes'

- name: 'Setup prompt configuration'
template:
src: 'kube-ps1-settings.sh.j2'
dest: '/etc/profile.d/kube-ps1-settings.sh'
owner: 'root'
group: 'root'
mode: 0644
become: 'yes'
...
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

export KUBE_PS1_BINARY={{ kubeps1_binary | quote }}
export KUBE_PS1_NS_ENABLE={{ kubeps1_ns_enabled | to_json }}
export KUBE_PS1_PREFIX={{ kubeps1_prefix | quote }}
export KUBE_PS1_SYMBOL_ENABLE={{ kubeps1_symbol_enabled | to_json }}
export KUBE_PS1_SYMBOL_PADDING={{ kubeps1_symbol_padding | to_json }}
export KUBE_PS1_SYMBOL_USE_IMG={{ kubeps1_symbol_use_img | to_json }}
export KUBE_PS1_SEPARATOR={{ kubeps1_separator | quote }}
export KUBE_PS1_DIVIDER={{ kubeps1_divider | quote }}
export KUBE_PS1_SUFFIX={{ kubeps1_suffix | quote }}
export KUBE_PS1_PREFIX_COLOR={{ kubeps1_prefix_color | quote }}
export KUBE_PS1_SYMBOL_COLOR={{ kubeps1_symbol_color | quote }}
export KUBE_PS1_CTX_COLOR={{ kubeps1_ctx_color | quote }}
export KUBE_PS1_SUFFIX_COLOR={{ kubeps1_suffix_color | quote }}
export KUBE_PS1_NS_COLOR={{ kubeps1_ns_color | quote }}
export KUBE_PS1_BG_COLOR={{ kubeps1_bg_color | quote }}
{% if (kubeps1_cluster_function is defined) and (kubeps1_cluster_function_name is defined) %}
{{ kubeps1_cluster_function }}
export KUBE_PS1_CLUSTER_FUNCTION={{ kubeps1_cluster_function_name }}
{% endif %}
{% if (kubeps1_namespace_function is defined) and (kube_namespace_function_name is defined) %}
{{ kubeps1_namespace_function }}
export KUBE_PS1_NAMESPACE_FUNCTION={{ kubeps1_namespace_function_name }}
{% endif %}
4 changes: 4 additions & 0 deletions provisioners/ansible/roles/kubernetes/kubeps1/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
kubeps1_repository: 'git@github.com:jonmosco/kube-ps1.git'
kubeps1_checkout_dir: '/tmp/kubeps1'
...
10 changes: 10 additions & 0 deletions provisioners/ansible/roles/system/bash_profile/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,14 @@
if [ -f ~/.fzf.bash ]; then
. ~/.fzf.bash
fi
- name: 'Set Kube-PS1 (kubernetes) prompt'
blockinfile:
path: '{{ bash_profile_path }}'
marker: '# {mark} ANSIBLE MANAGED BLOCK Kube-PS1 prompt'
state: 'present'
block: |
if [ -f /etc/profile.d/kube-ps1.sh ]; then
export PS1="\$(kube_ps1)$PS1"
fi
...

0 comments on commit 1d0c82d

Please sign in to comment.