Repository navigation
Closed
Labels
affects_2.10featureThis issue/PR relates to a feature requesthas_prmodulemodulepluginsplugin (any type)waiting_on_contributorNeeds help. Feel free to engage to get things unblocked
Description
From @tinyzimmer on Jan 02, 2019 20:09
SUMMARY
Using the aws_ssm lookup plugin to fetch an application secret, if the parameter does not exist, the plugin will fail silently setting an empty string for the queried value.
ISSUE TYPE
- Bug Report
COMPONENT NAME
aws_ssm
ANSIBLE VERSION
2.7.5
CONFIGURATION
user@somecomputer /cygdrive/c/Users/{{ redacted }}/Development/{{ redacted }}
$ ansible-config dump --only-changed
user@somecomputer /cygdrive/c/Users/{{ redacted }}/Development/{{ redacted }}
$
OS / ENVIRONMENT
Running in Cygwin on Windows 10 Pro (work computer 🤢) but likely affects other platforms?
STEPS TO REPRODUCE
# test.yml
- name: Test Param Retrieval
hosts: localhost
gather_facts: false
tasks:
# I'd expect this to fail
- set_fact:
test_var: "{{ lookup('aws_ssm', 'nonexistant_param', region='us-east-1') }}"
- debug:
var: test_varEXPECTED RESULTS
Fail because of non-existent parameter. Since it wasn't failing, I had no idea I was using the wrong AWS Shared Credentials Profile on the computer I was running this from. If this is expected behavior I suppose that's fine, but I don't see why it would be.
ACTUAL RESULTS
Playbook continues and any templates that use that value set it to an empty string
$ ansible-playbook test.yml
[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note
that the implicit localhost does not match 'all'
PLAY [Test Param Retrieval] ****************************************************
TASK [set_fact] ****************************************************************
ok: [localhost]
TASK [debug] *******************************************************************
ok: [localhost] => {
"test_var": ""
}
PLAY RECAP *********************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0Copied from original issue: ansible/ansible#50466
Metadata
Metadata
Assignees
Labels
affects_2.10featureThis issue/PR relates to a feature requesthas_prmodulemodulepluginsplugin (any type)waiting_on_contributorNeeds help. Feel free to engage to get things unblocked
Activity
Akasurde commentedon Aug 11, 2020
From @Edward-Ireson on Nov 19, 2019 16:32
I had the same issue and had to work around it, I did
"{{ lookup('aws_ssm', '/var/var1', region='eu-west-2', shortnames=true ) | default(NULL,true) }}"
The lookup is passed an empty result which because of the true flag tries to set the default to NULL which then fails because NULL is not defined.
ansibullbot commentedon Aug 27, 2020
cc @jillr @lwade @s-hertel @tremble @wimnat
click here for bot help
markuman commentedon Dec 6, 2020
it looks like that this behaviour is by design.
Furthermore, the documentation mentioned this behaviour also.
https://docs.ansible.com/ansible/latest/collections/amazon/aws/aws_ssm_lookup.html
JonTheNiceGuy commentedon Dec 7, 2020
NULL isn't defined. You're probably want something like this:
or
I don't believe any lookup will cause a "fail" state to occur.
tremble commentedon Dec 7, 2020
The aws_secrets lookup recently added support for on_missing and on_denied (#122)
A similar PR for aws_ssm might be a nice solution here.
2 remaining items
ansibullbot commentedon Jul 1, 2021
cc @linabuzachis
click here for bot help
aws_ssm add on_missing and on_denied options (#378)
ci(deps): bump the github-actions group with 7 updates (#3048)