Ansible Ad-hoc Command

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. :wink:

Thanks
Bipin

This will run the pwd command in the /etc directory

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

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