diff options
author | Bartek Grzybowski <b.grzybowski@partner.samsung.com> | 2020-09-15 16:51:24 +0200 |
---|---|---|
committer | Bartek Grzybowski <b.grzybowski@partner.samsung.com> | 2020-09-17 10:27:42 +0200 |
commit | e2b009b1c28575e34904b9f2275ced1c4ec06fec (patch) | |
tree | cc811af84d704a048605226fb4f7bf973c463a3f /ansible/roles/kubectl | |
parent | f6c503b35aa9f999b0cff39bb305308e03afb80a (diff) |
Add feature to install shell autocompletion for kubectl
Change-Id: I732dcd92144f9a8489a351047ab88b53ca36759e
Issue-ID: OOM-2564
Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
Diffstat (limited to 'ansible/roles/kubectl')
-rw-r--r-- | ansible/roles/kubectl/defaults/main.yml | 2 | ||||
-rw-r--r-- | ansible/roles/kubectl/molecule/default/tests/test_default.py | 4 | ||||
-rw-r--r-- | ansible/roles/kubectl/tasks/main.yml | 22 |
3 files changed, 28 insertions, 0 deletions
diff --git a/ansible/roles/kubectl/defaults/main.yml b/ansible/roles/kubectl/defaults/main.yml index b922fb58..5c2a4c69 100644 --- a/ansible/roles/kubectl/defaults/main.yml +++ b/ansible/roles/kubectl/defaults/main.yml @@ -1,2 +1,4 @@ --- kubectl_bin_dir: /usr/local/bin +completion_dir: /etc/bash_completion.d +completion_package: bash-completion diff --git a/ansible/roles/kubectl/molecule/default/tests/test_default.py b/ansible/roles/kubectl/molecule/default/tests/test_default.py index 4f799b95..3f4c7c7d 100644 --- a/ansible/roles/kubectl/molecule/default/tests/test_default.py +++ b/ansible/roles/kubectl/molecule/default/tests/test_default.py @@ -9,3 +9,7 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( def test_kubectl(host): assert host.file('/usr/local/bin/kubectl').exists assert host.run('kubectl').rc != 127 + + +def test_kubectl_bash_completion(host): + assert host.file('/etc/bash_completion.d/kubectl').exists diff --git a/ansible/roles/kubectl/tasks/main.yml b/ansible/roles/kubectl/tasks/main.yml index 7c77c3c5..03b9f9b0 100644 --- a/ansible/roles/kubectl/tasks/main.yml +++ b/ansible/roles/kubectl/tasks/main.yml @@ -5,3 +5,25 @@ dest: "{{ kubectl_bin_dir }}/kubectl" remote_src: true mode: 0755 + +- name: Install completion for the bash shell + package: + name: "{{ completion_package }}" + state: present + +- name: Generate shell autocompletion code for kubectl + command: kubectl completion bash + register: kubectl_completion + changed_when: false + +- name: Ensure bash completion dir exists + file: + path: "{{ completion_dir }}" + state: directory + mode: 0755 + +- name: Install bash autocompletion code for kubectl + copy: + content: "{{ kubectl_completion.stdout }}" + dest: "{{ completion_dir }}/kubectl" + mode: 0644 |