# Setting environment variables at the task level

**URL:** <https://forum.ansible.com/t/setting-environment-variables-at-the-task-level/44373>\
**Category:** Get Help\
**Tags:** task, playbook\
**Created:** [August 26, 2025, 3:33pm UTC](https://forum.ansible.com/t/setting-environment-variables-at-the-task-level/44373 "2025-08-26T15:33:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RSchulze](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/rschulze/32/9329_2.png) [@RSchulze](https://forum.ansible.com/u/RSchulze)\
**Post date:** [August 26, 2025, 3:33pm UTC](https://forum.ansible.com/t/setting-environment-variables-at-the-task-level/44373/1 "2025-08-26T15:33:08Z")

</div>

Hi,

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

```auto
[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](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_environment.html)

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

```auto
---
- 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?

---

<div class="post-metadata">

**Author:** ![flowerysong](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/flowerysong/32/2305_2.png) [@flowerysong](https://forum.ansible.com/u/flowerysong)\
**Post date:** [August 26, 2025, 6:26pm UTC](https://forum.ansible.com/t/setting-environment-variables-at-the-task-level/44373/2 "2025-08-26T18:26:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![RSchulze](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/rschulze/32/9329_2.png) [@RSchulze](https://forum.ansible.com/u/RSchulze)\
**Post date:** [August 27, 2025, 9:26am UTC](https://forum.ansible.com/t/setting-environment-variables-at-the-task-level/44373/3 "2025-08-27T09:26:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [September 26, 2025, 9:26am UTC](https://forum.ansible.com/t/setting-environment-variables-at-the-task-level/44373/4 "2025-09-26T09:26:32Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
