# Using an environment variable in dynamic inventory

**URL:** <https://forum.ansible.com/t/using-an-environment-variable-in-dynamic-inventory/32859>\
**Category:** Ansible Project\
**Tags:** azure\
**Created:** [May 6, 2020, 8:43am UTC](https://forum.ansible.com/t/using-an-environment-variable-in-dynamic-inventory/32859 "2020-05-06T08:43:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Marshall](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@Andrew\_Marshall](https://forum.ansible.com/u/Andrew_Marshall)\
**Post date:** [May 6, 2020, 8:43am UTC](https://forum.ansible.com/t/using-an-environment-variable-in-dynamic-inventory/32859/1 "2020-05-06T08:43:13Z")

</div>

Hi -

I have a basic dynamic inventory using the azure plugin:

```auto

plugin: azure_rm

include_vm_resource_groups:
- my_resource_group

```

However, this script runs in CI and teh resource group is created by a previous step, so it is not static. What I really want to do is this:

```auto

plugin: azure_rm

include_vm_resource_groups:
- "{{ lookup('env', 'MY_RESOURCE_GROUP') }}"

```

However the lookup syntax doesn’t work here, and the variable is not expanded. I have a temporary solution using sed to replace the variable on the fly, but is there a more elegant solution?

Thanks,  
Andrew.

---

<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:** [May 6, 2020, 2:22pm UTC](https://forum.ansible.com/t/using-an-environment-variable-in-dynamic-inventory/32859/2 "2020-05-06T14:22:11Z")

</div>

IT is something I've been trying to add  
[https://github.com/ansible/ansible/pull/58288](https://github.com/ansible/ansible/pull/58288)
