-
Notifications
You must be signed in to change notification settings - Fork 397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't pass a dictionary through included task to aws_secret #656
Comments
Files identified in the description: If these files are inaccurate, please update the |
Thanks for taking the time to open this issue. I'm trying to understand what you're actually expecting to see happen here. The APIs support two types of data "string" and "binary", there is no option to pass JSON / dictionaries into the secrets. The closest we can approximate a dictionary to is the string The warning is a side effect of Ansible trying to be clever and converting the string from "to_json" back into a dictionary (not something we can control in this collection). The easiest way to get rid of the warning would be
Which prevents the Ansible side of things trying to be clever, but that's still feeding the same thing only with some additional whitespace into the module. Is that what you're trying to achieve? Unfortunately in the expected results you're rather vague, what exactly (preferably with a example) are you expecting to see. If you're referring to the use of single quotes rather than double quotes, then the |
@tremble i think i might have run into the same, since i am new, i probably am just using the syntax wrong.
when i retrieve the value, it is formatted as key and value properly (the value is a json string with double quotes). The following syntax doesn't seem to work:
it will result in the following warning:
In the vault i just used
EDIT: I noticed using an inline vault, like this works as well:
|
Hi @tremble I am having the same issue as @nick-zh, it appears the module does not parse strings as key/value pairs when using variables.
|
Thanks for the extra info. Unfortunately this is primarily a limitation of Ansible itself. What the devs said over on IRC:
In theory we can hack around this by converting things back to JSON if they're passed to us as a dict/list, but it's not a brilliant solution. Unfortunately the original implementation used secret for both the binary and string input, which means we can't just tell Ansible that it's a string we expect. What you can try is
|
@tremble thx a lot for the elaboration and the follow up 🙏 |
@tremble I wonder if adding a json_string type that would make sure the string remains a valid json would not allow to fix this. wdyt ? I could do the PR if that seems a good solution. |
secretsmanager_secret - Support adding JSON SUMMARY fixes: #656 Amazon supports passing JSON in as the secret as a mechanism for storing and retreiving more complex structures. While in theory it's possible to pass JSON in as a string to secretsmanager_secret. However, because Ansible often does funky things with when templated strings are passed to a parameter (#656) it's non-trivial to pass JSON into secretsmanager_secret. ISSUE TYPE Feature Pull Request COMPONENT NAME secretsmanager_secret ADDITIONAL INFORMATION Backstory: If Ansible sees {{ }} within a string it'll trigger the safe_eval handlers, automatically converting the JSON into a complex structure of lists/dicts, which is then converted to the python string representation of the complex structures - the python string representation is not valid JSON and breaks the AWS integration. Reviewed-by: Joseph Torcasso <None>
secretsmanager_secret - Support adding JSON SUMMARY fixes: #656 Amazon supports passing JSON in as the secret as a mechanism for storing and retreiving more complex structures. While in theory it's possible to pass JSON in as a string to secretsmanager_secret. However, because Ansible often does funky things with when templated strings are passed to a parameter (#656) it's non-trivial to pass JSON into secretsmanager_secret. ISSUE TYPE Feature Pull Request COMPONENT NAME secretsmanager_secret ADDITIONAL INFORMATION Backstory: If Ansible sees {{ }} within a string it'll trigger the safe_eval handlers, automatically converting the JSON into a complex structure of lists/dicts, which is then converted to the python string representation of the complex structures - the python string representation is not valid JSON and breaks the AWS integration. Reviewed-by: Joseph Torcasso <None> (cherry picked from commit 5097a76)
[PR #1333/5097a76d backport][stable-4] secretsmanager_secret - Support adding JSON This is a backport of PR #1333 as merged into main (5097a76). SUMMARY fixes: #656 Amazon supports passing JSON in as the secret as a mechanism for storing and retreiving more complex structures. While in theory it's possible to pass JSON in as a string to secretsmanager_secret. However, because Ansible often does funky things with when templated strings are passed to a parameter (#656) it's non-trivial to pass JSON into secretsmanager_secret. ISSUE TYPE Feature Pull Request COMPONENT NAME secretsmanager_secret ADDITIONAL INFORMATION Backstory: If Ansible sees {{ }} within a string it'll trigger the safe_eval handlers, automatically converting the JSON into a complex structure of lists/dicts, which is then converted to the python string representation of the complex structures - the python string representation is not valid JSON and breaks the AWS integration. Reviewed-by: Mark Chappell <None>
Summary
When I wrap aws_secret into the task file with parameters and passing a dictionary with or without
to_nice_json
filter always get the warningNeedless to say this is not a JSON that I want for my secret.
Here is the contents of the
upload-secret.yml
Here is the call site
vars/main.yml
Passing the same dictionary to
community.aws.aws_secret
task does not produce the warning and results in correct JSON in the secretIssue Type
Bug Report
Component Name
aws_secret
Ansible Version
Collection Versions
$ ansible-galaxy collection list
AWS SDK versions
$ pip show boto boto3 botocore
Configuration
$ ansible-config dump --only-changed
OS / Environment
No response
Steps to Reproduce
See the description
Expected Results
See the description
Actual Results
Code of Conduct
The text was updated successfully, but these errors were encountered: