Ansible Ad-hoc Command

24 views
Skip to first unread message

Bipin Guragain

unread,
Mar 1, 2019, 2:36:02 AM3/1/19
to Ansible Project
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 

Kai Stian Olstad

unread,
Mar 1, 2019, 4:08:11 AM3/1/19
to ansible...@googlegroups.com
This will run the pwd command in the /etc directory

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


--
Kai Stian Olstad

Jeffrey Agnitsch

unread,
Mar 1, 2019, 9:34:32 AM3/1/19
to Ansible Project
This is a format that I use but as long as you cover all the required info you'll be good.

ansible -i <inventory file>  -m <the module> -a '< arugments>'  which hosts,  you can do I believe all, individual severs separated by commas as well as groups within the inventory file 
Reply all
Reply to author
Forward
0 new messages