Ansible解析了我的YML注释,并将其误认为k=v



在此代码块中运行ansible 2.9.6:

//System/group_vars/all/vars.yml

---
# AWS S3
# User Ansible
# Permissions put/get on arn:aws:s3:::snap/backup-db/*
# Plus d'infos: https://console.aws.amazon.com/iam/home?region=eu-west-2#/users/ansible?section=permissions
s3_access_key: {{ lookup('aws_ssm', '/iam/ansible/access-key', region='eu-west-2', aws_access_key=aws_access_key, aws_secret_key=aws_secret_key) }}

给出以下错误:

ERROR! Syntax Error while loading YAML.
found unacceptable key (unhashable type: 'AnsibleMapping')
The error appears to be in 'System/group_vars/all/vars.yml': line 32, column 63, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
# Plus d'infos: https://console.aws.amazon.com/iam/home?region=eu-west-2
^ here
There appears to be both 'k=v' shorthand syntax and YAML in this task. Only one syntax may be used.
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"

它认为region=eu-west-2是一个混合了YML语法的键值。

我该怎么做才能避免Ansible抛出这个错误,因为它在YML评论中?

谢谢:(

这是一个愚蠢的错误,原因是紧接在这一行之后的一行

# Plus d'infos: https://console.aws.amazon.com/iam/home?region=eu-west-2#/users/ansible?section=permissions
s3_access_key: {{ lookup('aws_ssm', '/iam/ansible/access-key', region='eu-west-2', aws_access_key=aws_access_key, aws_secret_key=aws_secret_key) }}

应为:

# Plus d'infos: https://console.aws.amazon.com/iam/home?region=eu-west-2#/users/ansible?section=permissions
s3_access_key: "{{ lookup('aws_ssm', '/iam/ansible/access-key', region='eu-west-2', aws_access_key=aws_access_key, aws_secret_key=aws_secret_key) }}"

注意"{{ lookup }}"周围的引号。错误消息试图告诉我,所以在错误的最后一部分("可能是缺少引号"(我只是专注于为什么我的评论被解析并解释为key=value

最新更新