[ANSIBLE] Setup cmctl autocompletion

Bash autocompletion code is generated to facilitate autocompletion
for cmctl command.

Change-Id: I03494293bf91aada54af70f6e0fd2c49e2feea64
Issue-ID: OOM-2871
Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
diff --git a/ansible/roles/cert-manager/defaults/main.yml b/ansible/roles/cert-manager/defaults/main.yml
index aa59c24..81a66f4 100644
--- a/ansible/roles/cert-manager/defaults/main.yml
+++ b/ansible/roles/cert-manager/defaults/main.yml
@@ -7,3 +7,5 @@
   helm_values:
     installCRDs: true
 cmctl_bin_dir: /usr/local/bin
+completion_dir: /etc/bash_completion.d
+completion_package: bash-completion
diff --git a/ansible/roles/cert-manager/tasks/main.yml b/ansible/roles/cert-manager/tasks/main.yml
index 9bf7fde..7706365 100644
--- a/ansible/roles/cert-manager/tasks/main.yml
+++ b/ansible/roles/cert-manager/tasks/main.yml
@@ -29,3 +29,25 @@
       - 'cmctl'
     remote_src: true
     mode: 0755
+
+- name: Install completion for the bash shell
+  package:
+    name: "{{ completion_package }}"
+    state: present
+
+- name: Generate shell autocompletion code for cmctl
+  command: cmctl completion bash
+  register: cmctl_completion
+  changed_when: false
+
+- name: Ensure bash completion dir exists
+  file:
+    path: "{{ completion_dir }}"
+    state: directory
+    mode: 0755
+
+- name: Install bash autocompletion code for cmctl
+  copy:
+    content: "{{ cmctl_completion.stdout }}"
+    dest: "{{ completion_dir }}/cmctl"
+    mode: 0644