# Ansible Ad-hoc Command

**URL:** <https://forum.ansible.com/t/ansible-ad-hoc-command/29804>\
**Category:** Ansible Project\
**Created:** [March 1, 2019, 7:36am UTC](https://forum.ansible.com/t/ansible-ad-hoc-command/29804 "2019-03-01T07:36:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bipin\_Guragain](https://avatars.discourse-cdn.com/v4/letter/b/ed655f/32.png) [@Bipin\_Guragain](https://forum.ansible.com/u/Bipin_Guragain)\
**Post date:** [March 1, 2019, 7:36am UTC](https://forum.ansible.com/t/ansible-ad-hoc-command/29804/1 "2019-03-01T07:36:01Z")

</div>

Hi All

I am new to Ansible and started using it for a while. I have one question on Ansible Ad-hoc command using a shell module with a passed args ‘chdir’. I am having a problem using the argument ‘chdir’ in Ansible CLI. The same works if i try to include in my playbook but don’t know why it can’t be accomplished via CLI.

Few question that came across on my mind

1. Are all the features supported in playbook is equally supported in Ansible CLI ?

2. If the step 1 is true then what is the best pattern to pass args in CLI?

The command that I try to execute via CLI is

ansible all -m shell -a “chdir /tmp ; wc-l” (–consider every set up and connection has been established between all of my hosts defined in default inventory file )

In a nutshell–I am trying to change the directory using chdir only via CLI.

Any suggestion will be really appreciated for this newbie. 😉

Thanks  
Bipin

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 1, 2019, 9:08am UTC](https://forum.ansible.com/t/ansible-ad-hoc-command/29804/2 "2019-03-01T09:08:00Z")

</div>

This will run the pwd command in the /etc directory

ansible all -m shell -a 'pwd chdir=/etc'

---

<div class="post-metadata">

**Author:** ![Jeffrey\_Agnitsch](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@Jeffrey\_Agnitsch](https://forum.ansible.com/u/Jeffrey_Agnitsch)\
**Post date:** [March 1, 2019, 2:34pm UTC](https://forum.ansible.com/t/ansible-ad-hoc-command/29804/3 "2019-03-01T14:34:32Z")

</div>

This is a format that I use but as long as you cover all the required info you’ll be good.

ansible -i -m -a ‘\< arugments\>’ which hosts, you can do I believe all, individual severs separated by commas as well as groups within the inventory file
