Add feature to install shell autocompletion for kubectl 05/112705/6
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>
Tue, 15 Sep 2020 14:51:24 +0000 (16:51 +0200)
committerBartek Grzybowski <b.grzybowski@partner.samsung.com>
Thu, 17 Sep 2020 08:27:42 +0000 (10:27 +0200)
Change-Id: I732dcd92144f9a8489a351047ab88b53ca36759e
Issue-ID: OOM-2564
Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
ansible/roles/kubectl/defaults/main.yml
ansible/roles/kubectl/molecule/default/tests/test_default.py
ansible/roles/kubectl/tasks/main.yml
build/data_lists/onap_deb.list
build/data_lists/onap_rpm.list

index b922fb5..5c2a4c6 100644 (file)
@@ -1,2 +1,4 @@
 ---
 kubectl_bin_dir: /usr/local/bin
+completion_dir: /etc/bash_completion.d
+completion_package: bash-completion
index 4f799b9..3f4c7c7 100644 (file)
@@ -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
index 7c77c3c..03b9f9b 100644 (file)
@@ -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
index fcc6391..44ccf60 100644 (file)
@@ -55,3 +55,4 @@ libc-dev
 make
 binutils
 resolvconf
+bash-completion
index c369de0..b906e03 100644 (file)
@@ -1,4 +1,5 @@
 audit-libs-python-2.8.4-4.el7.x86_64
+bash-completion-2.1-8.el7.noarch
 checkpolicy-2.5-8.el7.x86_64
 containerd.io-1.2.5-3.1.el7.x86_64
 container-selinux-2.107-1.el7_6.noarch