3 # Copyright (c) 2020 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
19 function ansible_adhoc () {
21 # Run ansible ad-hoc command module on hosts in working topology file.
24 # - ${WORKING_TOPOLOGY} - Reserved working topology.
25 # - ${TOOLS_DIR} - CSIT tools directory, where testbed-setup is located.
29 if ! installed sshpass; then
30 die "Please install sshpass!"
33 hosts=($(fgrep host "${WORKING_TOPOLOGY}" | cut -d ":" -f 2)) || {
34 die "Failed to read hosts from working topology!"
36 pushd "${TOOLS_DIR}"/testbed-setup/ansible || die "Pushd failed!"
37 ANSIBLE_STDOUT_CALLBACK=yaml ansible \
38 --vault-password-file=vault_pass \
39 --extra-vars '@vault.yml' \
40 --inventory inventories/lf_inventory/hosts site.yaml \
41 --limit "$(echo ${hosts[@]//\"})" \
43 --args \"$(echo $@)\" || die "Failed to run ansible on host!"
44 popd || die "Popd failed!"
47 function ansible_playbook () {
49 # Run ansible playbook on hosts in working topology file. Ansible scope is
50 # determined by tags passed as parameters to this function.
53 # - ${WORKING_TOPOLOGY} - Reserved working topology.
54 # - ${TOOLS_DIR} - CSIT tools directory, where testbed-setup is located.
58 if ! installed sshpass; then
59 die "Please install sshpass!"
62 hosts=($(fgrep host "${WORKING_TOPOLOGY}" | cut -d ":" -f 2)) || {
63 die "Failed to read hosts from working topology!"
65 pushd "${TOOLS_DIR}"/testbed-setup/ansible || die "Pushd failed!"
66 ANSIBLE_STDOUT_CALLBACK=yaml ansible-playbook \
67 --vault-password-file=vault_pass \
68 --extra-vars '@vault.yml' \
69 --inventory inventories/lf_inventory/hosts site.yaml \
70 --limit "$(echo ${hosts[@]//\"})" \
71 --tags "$(echo $@)" || die "Failed to run ansible on host!"
72 popd || die "Popd failed!"
76 function installed () {
78 # Check if the given utility is installed. Fail if not installed.
81 # - ${1} - Utility to check.
82 # Returns (implicitly):
83 # - 0 - If command is installed.
84 # - 1 - If command is not installed.