I have a problem with passing parameters to the Ansible:
Bash script:
#!/usr/bin/env bash
set -e +x
# Variables
LINUX_HOST="ubuntu"
INSTALL_ANSIBLE_TARGET_PATH="/tmp/ansible-inst"
ANSIBLE_CONFIG_DIR="inventory"
ANSIBLE_CONFIG_FILENAME="hosts.yml"
ANSIBLE_PLAYBOOKS_DIR="playbooks"
ANSIBLE_PREPARE_PLAYBOOK_FILENAME="linux-prepare-deploy.yml"
ANSIBLE_POSTGRES_PLAYBOOK_FILENAME="postgresql-server-install.yml"
ANSIBLE_POSTGRES_PLAYBOOK_PARAMETER=" -e \"POSTGRES_cluster_name=ansiblecluster\""
# Utils
run_playbook() {
LOG_MSG="Running playbook ${1}"
if [ "${2}" != "" ]; then
LOG_MSG="${LOG_MSG} with additional parameters ${2}"
fi
ANSIBLE_CONFIG_FILE="${INSTALL_ANSIBLE_TARGET_PATH}/${ANSIBLE_CONFIG_DIR}/${ANSIBLE_CONFIG_FILENAME}"
log_i "${LOG_MSG} using main config ${ANSIBLE_CONFIG_FILE} file."
sudo ansible-playbook -i "${ANSIBLE_CONFIG_FILE}" -l "${LINUX_HOST}" "${1}" "${2}"
log_i "Ansible playbook ${1} execution was finished."
}
# Main functions
_ansible_run() {
cd "${INSTALL_ANSIBLE_TARGET_PATH}"
PLAYBOOKS_DIRECTORY="${INSTALL_ANSIBLE_TARGET_PATH}/${ANSIBLE_PLAYBOOKS_DIR}"
run_playbook "${PLAYBOOKS_DIRECTORY}/${ANSIBLE_PREPARE_PLAYBOOK_FILENAME}" ""
run_playbook "${PLAYBOOKS_DIRECTORY}/${ANSIBLE_POSTGRES_PLAYBOOK_FILENAME}" "${ANSIBLE_POSTGRES_PLAYBOOK_PARAMETER}"
}
But after execute _ansible_run
I got this output:
[ANSIBLE] 2023-07-06 10:54:04 INFO : Running playbook /tmp/ansible-inst/playbooks/prepare-deploy.yml using main config /tmp/ansible-inst/inventory/hosts.yml file.
ERROR! the playbook: could not be found
It looks like the parameters are not passed, but I don't understand how to fix this. Can you help me please?