I need to lookup a value from AWS SSM Parameter Store, but it needs to fail if the parameter type is secure string.
I do NOT want secure string parameters to be decrypted, and I want to detect their type and fail gracefully.
- name: Get the value from AWS Parameter Store
set_fact:
var_value: "{{ lookup('aws_ssm', var_path, decrypt=False, region=aws_region, aws_access_key=aws_access_key, aws_secret_key=aws_secret_key) }}"
- name: Show the value
debug:
msg:
- "VALUE: {{ var_value | default( 'FAILED_TO_DECRYPT' ) }}"
However, the aws_ssm
module does not fail when told not to decrypt a secure string. It returns the encrypted string (not helpful). I don't see a way to detect parameter type.
TASK [Show the value] **********************************************************
ok: [127.0.0.1] => {
"msg": [
"VALUE: CRAZY_LONG_ENCRYPTED_STRING_AND_NOT_THE_REAL_VALUE"
]
}
What is a best practice for intentionally failing to decrypt secure strings?
References:
{{ lookup('aws_ssm', '{{ var_path }}') }}
should instead be{{ lookup('aws_ssm', var_path) }}
. Once you are in a Jinja expression you do not need additional delimiters.