我已经创建了一个sns发布ansible play book并试图运行它,但它没有工作并给我错误..我发送整个 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 undefined\n\nThe 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 may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Publish Jenkins Error to SNS topic for failures\n ^ here\n"
}
调用脚本是
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"
任何帮助将不胜感激
答案 0 :(得分:0)
我能解决这个问题..似乎ansible编译冒号有问题:发送为参数。您必须在双引号之间发送参数值才能使其工作。例如,arn将显示为“arn:dfd:dfdf ....”