Ansible 2.9.11 > 2.10.3 env lookup giving lookups were disabled from templating error

Hi,

Doing a soak test on upgrading from Ansible 2.9.11 to 2.10.3 as I want to use some new features in a collection. Getting the following error on the following variable:

deploy_version: “locally deployed by {{ lookup(‘env’, ‘ANSIBLE_CALLER_USERNAME’) }}”

The error being returned is:

Error was a <class ‘ansible.errors.AnsibleError’>, original message: The lookup env was found, however lookups were disabled from templating

Any suggestions as to what is causing this?

Thanks.
Andrew.

Hi,

that change was apparently caused by https://github.com/ansible/ansible/pull/69278

I have no idea why it was made, though.

Cheers,
Felix

Felix Fontein wrote:

Hi,

that change was apparently caused by https://github.com/ansible/ansible/pull/69278

I have no idea why it was made, though.

I have done further digging on this and come up with the following:

The template in question is actually used as part of a dictionary:

# Define the resource tags
# If not updated by the CI system, put a placeholder deploy tag which indicates local deployment
# ANSIBLE_CALLER_USERNAME environment variable is set using the Docker wrapper script
deploy_version: "locally deployed by {{ lookup('env', 'ANSIBLE_CALLER_USERNAME') }}"

resource_tags:
  Platform: "{{ platform_name }}"
  Stage: "{{ environment_type }}"
  DeployTag: "{{ deploy_version }}"

If I print this out in a debug statement then the tags dictionary is correct and also resources are deployed using the correct tags data. The part that is failing is an assertion:

- name: Validate variables that need to be defined by calling role
  assert:
    that: "{{ item }} is defined"
    msg: "Variable {{ item }} is not defined"
    quiet: yes
  with_items: "{{ required_vars | default ([]) }} "

In this example resource_tags is in a list of required_vars we want defining and its giving us the error at the point it tries to assert the variable exists.

Thanks.
Andrew.