summaryrefslogtreecommitdiffstats
path: root/ansible
diff options
context:
space:
mode:
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>2021-12-17 11:17:55 +0100
committerBartek Grzybowski <b.grzybowski@partner.samsung.com>2021-12-17 11:17:55 +0100
commit3a94af71ad65d2ec93b21cde755ec3a6430180ac (patch)
tree8219ab0428acbbf9354ac71acc9762c0863caa8a /ansible
parent7c1839f6063e55ba24143c6f8951966a99f6b797 (diff)
[ANSIBLE] Add 'bash-completion' role
Role installs bash-completion package and generates the shell completion code for binary given as a role parameter Change-Id: I95af7b7a16b0dec1dd7841f1db7afdb3738fe6bc Issue-ID: OOM-2902 Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
Diffstat (limited to 'ansible')
-rw-r--r--ansible/roles/bash-completion/.yamllint12
-rw-r--r--ansible/roles/bash-completion/README.md15
-rw-r--r--ansible/roles/bash-completion/defaults/main.yml3
-rw-r--r--ansible/roles/bash-completion/molecule/default/converge.yml7
-rw-r--r--ansible/roles/bash-completion/molecule/default/molecule.yml25
-rw-r--r--ansible/roles/bash-completion/molecule/default/prepare.yml7
-rw-r--r--ansible/roles/bash-completion/molecule/default/tests/test_default.py7
-rw-r--r--ansible/roles/bash-completion/tasks/main.yml22
8 files changed, 98 insertions, 0 deletions
diff --git a/ansible/roles/bash-completion/.yamllint b/ansible/roles/bash-completion/.yamllint
new file mode 100644
index 00000000..c5ae64be
--- /dev/null
+++ b/ansible/roles/bash-completion/.yamllint
@@ -0,0 +1,12 @@
+---
+extends: default
+
+rules:
+ braces:
+ max-spaces-inside: 1
+ level: error
+ brackets:
+ max-spaces-inside: 1
+ level: error
+ line-length: disable
+ truthy: disable
diff --git a/ansible/roles/bash-completion/README.md b/ansible/roles/bash-completion/README.md
new file mode 100644
index 00000000..d96e9165
--- /dev/null
+++ b/ansible/roles/bash-completion/README.md
@@ -0,0 +1,15 @@
+Role to install bash-completion
+===============================
+
+Role that installs the bash-completion package and generates the completion code for binary which name is passed via role parameter.
+
+Requirements
+------------
+
+For the role to operate properly it is expected that the binary for which the completion code is generated supports "completion bash" option.
+
+Role Variables
+--------------
+
+- completion\_bin (role's parameter) - name of the binary for which the completion code will be generated
+
diff --git a/ansible/roles/bash-completion/defaults/main.yml b/ansible/roles/bash-completion/defaults/main.yml
new file mode 100644
index 00000000..cc95f203
--- /dev/null
+++ b/ansible/roles/bash-completion/defaults/main.yml
@@ -0,0 +1,3 @@
+---
+completion_dir: /etc/bash_completion.d
+completion_package: bash-completion
diff --git a/ansible/roles/bash-completion/molecule/default/converge.yml b/ansible/roles/bash-completion/molecule/default/converge.yml
new file mode 100644
index 00000000..a58fee0f
--- /dev/null
+++ b/ansible/roles/bash-completion/molecule/default/converge.yml
@@ -0,0 +1,7 @@
+---
+- name: Converge
+ hosts: all
+ tasks:
+ - name: "Include bash-completion"
+ include_role:
+ name: "bash-completion"
diff --git a/ansible/roles/bash-completion/molecule/default/molecule.yml b/ansible/roles/bash-completion/molecule/default/molecule.yml
new file mode 100644
index 00000000..d30a084b
--- /dev/null
+++ b/ansible/roles/bash-completion/molecule/default/molecule.yml
@@ -0,0 +1,25 @@
+---
+dependency:
+ name: galaxy
+driver:
+ name: docker
+lint: |
+ set -e
+ yamllint .
+ ansible-lint .
+ flake8
+platforms:
+ - name: bash-completion
+ image: centos:7
+provisioner:
+ name: ansible
+ env:
+ ANSIBLE_ROLES_PATH: ../../../../test/roles
+ ANSIBLE_LIBRARY: ../../../../library
+ inventory:
+ group_vars:
+ all:
+ kubectl_install: true
+ completion_bin: kubectl
+verifier:
+ name: testinfra
diff --git a/ansible/roles/bash-completion/molecule/default/prepare.yml b/ansible/roles/bash-completion/molecule/default/prepare.yml
new file mode 100644
index 00000000..5acc39cd
--- /dev/null
+++ b/ansible/roles/bash-completion/molecule/default/prepare.yml
@@ -0,0 +1,7 @@
+---
+- name: Prepare
+ hosts: all
+ roles:
+ # This role is played in prepare stage only to install kubectl which will be
+ # used as a binary to test the bash-completion role
+ - prepare-kubectl
diff --git a/ansible/roles/bash-completion/molecule/default/tests/test_default.py b/ansible/roles/bash-completion/molecule/default/tests/test_default.py
new file mode 100644
index 00000000..5a66ee2d
--- /dev/null
+++ b/ansible/roles/bash-completion/molecule/default/tests/test_default.py
@@ -0,0 +1,7 @@
+def test_bash_completion(host):
+ assert host.package("bash-completion").is_installed
+
+
+def test_bash_completion_kubectl(host):
+ f = host.file('/etc/bash_completion.d/kubectl')
+ assert f.exists
diff --git a/ansible/roles/bash-completion/tasks/main.yml b/ansible/roles/bash-completion/tasks/main.yml
new file mode 100644
index 00000000..ef402e51
--- /dev/null
+++ b/ansible/roles/bash-completion/tasks/main.yml
@@ -0,0 +1,22 @@
+---
+- name: Install completion for the bash shell
+ package:
+ name: "{{ completion_package }}"
+ state: present
+
+- name: Ensure bash completion dir exists
+ file:
+ path: "{{ completion_dir }}"
+ state: directory
+ mode: 0755
+
+- name: Generate shell autocompletion code for {{ completion_bin }}
+ command: "{{ completion_bin }} completion bash"
+ register: bash_completion
+ changed_when: false
+
+- name: Install bash autocompletion code for {{ completion_bin }}
+ copy:
+ content: "{{ bash_completion.stdout }}"
+ dest: "{{ completion_dir }}/{{ completion_bin }}"
+ mode: 0644