# Is there a way to use variables with ad-hoc commands

**URL:** <https://forum.ansible.com/t/is-there-a-way-to-use-variables-with-ad-hoc-commands/16061>\
**Category:** Ansible Project\
**Created:** [August 28, 2014, 8:44am UTC](https://forum.ansible.com/t/is-there-a-way-to-use-variables-with-ad-hoc-commands/16061 "2014-08-28T08:44:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alain\_Kreienbuhl](https://avatars.discourse-cdn.com/v4/letter/a/e495f1/32.png) [@Alain\_Kreienbuhl](https://forum.ansible.com/u/Alain_Kreienbuhl)\
**Post date:** [August 28, 2014, 8:44am UTC](https://forum.ansible.com/t/is-there-a-way-to-use-variables-with-ad-hoc-commands/16061/1 "2014-08-28T08:44:13Z")

</div>

Hello,

I wanted to do that :

ansible -i inventories/production all -m shell -a "echo urok | nc {{ ansible\_eth1.ipv4.address }} 2181 "

But it it seams that vars are not supported within ad-hoc commands. Right ?

Thanks

Alain

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 28, 2014, 11:57am UTC](https://forum.ansible.com/t/is-there-a-way-to-use-variables-with-ad-hoc-commands/16061/2 "2014-08-28T11:57:16Z")

</div>

Variables are, including inventory variables and “-e”, but you cannot use fact gathering with /usr/bin/ansible, as they are a playbook only construct.

---

<div class="post-metadata">

**Author:** ![Alain\_Kreienbuhl](https://avatars.discourse-cdn.com/v4/letter/a/e495f1/32.png) [@Alain\_Kreienbuhl](https://forum.ansible.com/u/Alain_Kreienbuhl)\
**Post date:** [August 28, 2014, 12:27pm UTC](https://forum.ansible.com/t/is-there-a-way-to-use-variables-with-ad-hoc-commands/16061/3 "2014-08-28T12:27:41Z")

</div>

Ok thanks

---

<div class="post-metadata">

**Author:** ![Tomasz\_Kontusz](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@Tomasz\_Kontusz](https://forum.ansible.com/u/Tomasz_Kontusz)\
**Post date:** [August 28, 2014, 3:24pm UTC](https://forum.ansible.com/t/is-there-a-way-to-use-variables-with-ad-hoc-commands/16061/4 "2014-08-28T15:24:34Z")

</div>

Michael DeHaan \<michael@ansible.com\> napisał:

> Variables are, including inventory variables and "-e", but you cannot  
> use  
> fact gathering with /usr/bin/ansible, as they are a playbook only  
> construct.

Will fact caching change that? Or is bin/ansible not aware of the cache?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 28, 2014, 9:04pm UTC](https://forum.ansible.com/t/is-there-a-way-to-use-variables-with-ad-hoc-commands/16061/5 "2014-08-28T21:04:20Z")

</div>

Should change that, yes!
