From 36d56bdb7f9f394047e2df3f29bf47db877b649c Mon Sep 17 00:00:00 2001 From: Vratko Polak Date: Wed, 10 Jul 2019 13:59:50 +0200 Subject: Bash functions style cleanup + Update rst documentation for bash style + Command substitution: + Clarify when to use backticks. + Recommend avoiding nested command substitution. + Do not recommend putting command substitution results into quotes. + Function definition content: + Move "set -exuo pipefail" after comment only blocks. + Other set flags allowed for functions with good reasons. + Apply the new recommendations. - Blank lines unified in code but no written recommendation in rst. + Add missing references to functions called, variables read or set. + Add TODOs to where lists would be long. + Minor improvements to function descriptions. + Make "if" expressions more python-like. + Add missing "|| die" (or "|| true") where spotted. + Downgrade DEFAULT_NIC to a local variable. + Add TODO to list reasons for blacklisted tags. Change-Id: I05dce030a8c2cb1b3a242d8b977e8fe150d8ee20 Signed-off-by: Vratko Polak --- resources/libraries/bash/function/ansible.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'resources/libraries/bash/function/ansible.sh') diff --git a/resources/libraries/bash/function/ansible.sh b/resources/libraries/bash/function/ansible.sh index 663861e8d8..5bf122e4b0 100644 --- a/resources/libraries/bash/function/ansible.sh +++ b/resources/libraries/bash/function/ansible.sh @@ -17,6 +17,7 @@ set -exuo pipefail function ansible_hosts () { + # Run ansible playbook on hosts in working topology file. Ansible scope is # determined by tags passed as parameters to this function. # @@ -51,15 +52,15 @@ function ansible_hosts () { function installed () { - set -exuo pipefail - # Check if the given utility is installed. Fail if not installed. # # Arguments: # - ${1} - Utility to check. - # Returns: + # Returns (implicitly): # - 0 - If command is installed. # - 1 - If command is not installed. + set -exuo pipefail + command -v "${1}" -} \ No newline at end of file +} -- cgit 1.2.3-korg