Setting environment variables at the task level

Hi,

I recently updated my ansible to version 2.19 and have been getting the following warning:

[WARNING]: Found variable using reserved name 'environment'.

The thing is that I’m actually trying to set environment variables at the task level like described in the documentation: Setting the remote environment — Ansible Community Documentation

This is a minimal playbook used for testing to reproduce the problem.

---
- name: environment test
  hosts: 1.2.3.4

  tasks:
    - name: run apt upgrade
      ansible.builtin.apt:
        update_cache: true
        upgrade: "safe"
      environment:
        ACCEPT_EULA: 'Y'

Oddly ansible doesn’t throw a warning if run against localhost. So I assume it might by python3 specific (3.12.3 on the client, 3.10.12 on the server) or I’m using it wrong?

This playbook is not sufficient to replicate the output you received. Since the warning references a variable using a reserved name, it’s much more likely that you have a variable named environment set for this host than that Ansible is somehow misinterpreting the environment keyword.

Argh, thank you so much, the environment variable got injected via dynamic inventory. I never though to check in that direction.