3 # Copyright (c) 2024 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 # - ${CSIT_DIR} - CSIT main directory, where ansible playbooks are located.
26 # - ${FLAVOR} - Node flavor string, see common.sh
31 "aws" | "c6in" | "c6gn" | "c7gn")
32 INVENTORY_PATH="cloud_inventory"
35 INVENTORY_PATH="external_inventory"
38 INVENTORY_PATH="lf_inventory"
42 if ! installed sshpass; then
43 die "Please install sshpass!"
46 hosts=($(fgrep host "${WORKING_TOPOLOGY}" | cut -d ":" -f 2)) || {
47 die "Failed to read hosts from working topology!"
49 pushd "${CSIT_DIR}"/fdio.infra.ansible || die "Pushd failed!"
50 export ANSIBLE_HOST_KEY_CHECKING=False
51 export ANSIBLE_STDOUT_CALLBACK=yaml
52 export ANSIBLE_PIPELINING=true
54 --vault-password-file=vault_pass \
55 --extra-vars '@vault.yml' \
56 --inventory inventories/$INVENTORY_PATH/hosts site.yaml \
57 --limit "$(echo ${hosts[@]//\"})" \
59 --args \"$(echo $@)\" || die "Failed to run ansible on host!"
60 popd || die "Popd failed!"
63 function ansible_playbook () {
65 # Run ansible playbook on hosts in working topology file. Ansible scope is
66 # determined by tags passed as parameters to this function.
69 # - ${WORKING_TOPOLOGY} - Reserved working topology.
70 # - ${CSIT_DIR} - CSIT main directory, where ansible playbooks are located.
71 # - ${FLAVOR} - Node flavor string, see common.sh
76 "aws" | "c6in" | "c6gn" | "c7gn")
77 INVENTORY_PATH="cloud_inventory"
80 INVENTORY_PATH="external_inventory"
83 INVENTORY_PATH="lf_inventory"
87 if ! installed sshpass; then
88 die "Please install sshpass!"
91 hosts=($(fgrep host "${WORKING_TOPOLOGY}" | cut -d ":" -f 2)) || {
92 die "Failed to read hosts from working topology!"
94 pushd "${CSIT_DIR}"/fdio.infra.ansible || die "Pushd failed!"
95 export ANSIBLE_HOST_KEY_CHECKING=False
96 export ANSIBLE_STDOUT_CALLBACK=yaml
97 export ANSIBLE_PIPELINING=true
99 --vault-password-file=vault_pass \
100 --extra-vars '@vault.yml' \
101 --inventory inventories/$INVENTORY_PATH/hosts site.yaml \
102 --limit "$(echo ${hosts[@]//\"})" \
103 --tags "$(echo $@)" || die "Failed to run ansible on host!"
104 popd || die "Popd failed!"
108 function installed () {
110 # Check if the given utility is installed. Fail if not installed.
113 # - ${1} - Utility to check.
114 # Returns (implicitly):
115 # - 0 - If command is installed.
116 # - 1 - If command is not installed.