X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=resources%2Flibraries%2Fbash%2Ffunction%2Fansible.sh;h=1263412dd51ca6acab9eecce2bf563ca6c9c365f;hb=HEAD;hp=3beca3fba43c14434436a6560c43fd45357cc97a;hpb=df5672b3d9c29b51397f4770eb992c9f3f3955ce;p=csit.git diff --git a/resources/libraries/bash/function/ansible.sh b/resources/libraries/bash/function/ansible.sh index 3beca3fba4..6cf4d16f43 100644 --- a/resources/libraries/bash/function/ansible.sh +++ b/resources/libraries/bash/function/ansible.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# Copyright (c) 2021 Cisco and/or its affiliates. +# Copyright (c) 2024 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -23,9 +23,22 @@ function ansible_adhoc () { # Variable read: # - ${WORKING_TOPOLOGY} - Reserved working topology. # - ${CSIT_DIR} - CSIT main directory, where ansible playbooks are located. + # - ${FLAVOR} - Node flavor string, see common.sh set -exuo pipefail + case "$FLAVOR" in + "aws" | "c6in" | "c6gn" | "c7gn") + INVENTORY_PATH="cloud_inventory" + ;; + "x-"*) + INVENTORY_PATH="external_inventory" + ;; + *) + INVENTORY_PATH="lf_inventory" + ;; + esac + if ! installed sshpass; then die "Please install sshpass!" fi @@ -40,7 +53,7 @@ function ansible_adhoc () { ansible-playbook \ --vault-password-file=vault_pass \ --extra-vars '@vault.yml' \ - --inventory inventories/lf_inventory/hosts site.yaml \ + --inventory inventories/$INVENTORY_PATH/hosts site.yaml \ --limit "$(echo ${hosts[@]//\"})" \ --module-name shell \ --args \"$(echo $@)\" || die "Failed to run ansible on host!" @@ -55,9 +68,22 @@ function ansible_playbook () { # Variable read: # - ${WORKING_TOPOLOGY} - Reserved working topology. # - ${CSIT_DIR} - CSIT main directory, where ansible playbooks are located. + # - ${FLAVOR} - Node flavor string, see common.sh set -exuo pipefail + case "$FLAVOR" in + "aws" | "c6in" | "c6gn" | "c7gn") + INVENTORY_PATH="cloud_inventory" + ;; + "x-"*) + INVENTORY_PATH="external_inventory" + ;; + *) + INVENTORY_PATH="lf_inventory" + ;; + esac + if ! installed sshpass; then die "Please install sshpass!" fi @@ -72,7 +98,7 @@ function ansible_playbook () { ansible-playbook \ --vault-password-file=vault_pass \ --extra-vars '@vault.yml' \ - --inventory inventories/lf_inventory/hosts site.yaml \ + --inventory inventories/$INVENTORY_PATH/hosts site.yaml \ --limit "$(echo ${hosts[@]//\"})" \ --tags "$(echo $@)" || die "Failed to run ansible on host!" popd || die "Popd failed!"