使用 shell 脚本调用 SNS ansible 脚本



我创建了一个sns发布ansible剧本并尝试运行它,但它不起作用并给了我错误。我正在为该主题发送整个 arn。sns 组件是否不解析冒号

fatal: [localhost]: FAILED! => {
"failed": true, 
"msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'snsTopicName' is undefinednnThe error appears to have been in '/var/opt/jenkins/data/workspace/working/cicd-pipeline/working-cicd-pipeline/lib/helper/sns-publish.yml': line 25, column 7, but maynbe elsewhere in the file depending on the exact syntax problem.nnThe offending line appears to be:nnn    - name: Publish Jenkins Error to SNS topic for failuresn      ^ heren"
}

调用脚本是

if [ "$1" = "QA" ]
then
ansible-playbook -vvv -c local "sns-publishQA.yml" --extra-vars "environment:'$environment' snsTopicName:'$snsTopicName'"
else
ansible-playbook -vvv -c local "sns-publish.yml" --extra-vars "environment:'$environment' snsTopicName:'$snsTopicName'"
fi
if [[ $? -ne 0 ]]; then
exit 1
fi  
cd -  
}

剧本是

- name: Publish Jenkins Error to SNS topic {{snsTopicName}}
sns:
msg: "Error happened when running the pipeline"
subject: "Jenkins Error"
topic: "{{snsTopicName}}"
aws_access_key: "{{ assumed_role.sts_creds.access_key }}"
aws_secret_key: "{{ assumed_role.sts_creds.secret_key }}"
region: "us-east-1"

任何帮助将不胜感激

我能够解决这个问题。似乎 ansible 在编译冒号时出现问题:作为参数发送。您必须在双引号之间发送参数值才能完成此操作。例如,arn 将看起来"arn:dfd:dfdf....">

相关内容

  • 没有找到相关文章

最新更新