# ansible-shell

**URL:** <https://forum.ansible.com/t/ansible-shell/12927>\
**Category:** Ansible Project\
**Created:** [June 7, 2013, 9:47pm UTC](https://forum.ansible.com/t/ansible-shell/12927 "2013-06-07T21:47:44Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nandor\_Sivok](https://avatars.discourse-cdn.com/v4/letter/n/d6d6ee/32.png) [@Nandor\_Sivok](https://forum.ansible.com/u/Nandor_Sivok)\
**Post date:** [June 7, 2013, 9:47pm UTC](https://forum.ansible.com/t/ansible-shell/12927/1 "2013-06-07T21:47:44Z")

</div>

Hello Guys,

I’m using ansible cli a lot for my daily work to run commands simultaneously on our cluster. Mainly I’m using the shell module but sometimes easier to use the specified module for a job. However I always forgot the required arguments, even for the ones created by me. The other thing I always forgot is the group names in our hosts file.

So I’ve created a little interactive shell for ansible. It can complete the host names, host groups, module names and its arguments.

By default it’s using the shell if there is no matching module and there are three built in commands:

- cd - change to host/group
- serial - change the number of forks
- list - list the nodes in the current group

You can download from: [https://github.com/dominis/ansible-shell](https://github.com/dominis/ansible-shell)

At this point there is no installer just drop the file somewhere to your path and run it.

[root@cobbler dominis]# ansible-shell

Welcome to the ansible-shell.  
Type help or ? to list commands.

**dominis@/[s:2]$ cd app**  
app-pool [app02.bfc.kinja.com](http://app02.bfc.kinja.com) [app04.bfc.kinja.com](http://app04.bfc.kinja.com) [app06.bfc.kinja.com](http://app06.bfc.kinja.com) [app08.bfc.kinja.com](http://app08.bfc.kinja.com) [app10.bfc.kinja.com](http://app10.bfc.kinja.com) [app12.bfc.kinja.com](http://app12.bfc.kinja.com)  
[app01.bfc.kinja.com](http://app01.bfc.kinja.com) [app03.bfc.kinja.com](http://app03.bfc.kinja.com) [app05.bfc.kinja.com](http://app05.bfc.kinja.com) [app07.bfc.kinja.com](http://app07.bfc.kinja.com) [app09.bfc.kinja.com](http://app09.bfc.kinja.com) [app11.bfc.kinja.com](http://app11.bfc.kinja.com)  
**dominis@/[s:2]$ cd app-pool**  
**dominis@/app-pool (12)[s:2]$ ec2**  
ec2 ec2\_facts ec2\_vol  
**dominis@/app-pool (12)[s:2]$ ec2**  
count= ec2\_secret\_key= group= id= instance\_tags= kernel= monitor= user\_data= wait=  
ec2\_access\_key= ec2\_url= group\_id= image= instance\_type= key\_name= ramdisk= vpc\_subnet\_id= wait\_timeout=

**dominis@/app-pool (12)[s:2]$ help ec2**  
create an instance in ec2, return instanceid  
Paremeters:  
ramdisk ramdisk I(eri) to use for the instance  
kernel kernel I(eki) to use for the instance  
key\_name key pair to use on the instance  
image I(emi) (or I(ami)) to use for the instance  
vpc\_subnet\_id the subnet ID in which to launch the instance (VPC)  
user\_data opaque blob of data which is made available to the ec2 instance  
wait\_timeout how long before wait gives up, in seconds  
ec2\_url url to use to connect to EC2 or your Eucalyptus cloud (by default the module will use EC2 endpoints)  
ec2\_access\_key ec2 access key  
ec2\_secret\_key ec2 secret key  
id identifier for this instance or set of instances, so that the module will be idempotent with respect to EC2 instances.  
wait wait for the instance to be in state ‘running’ before returning  
count number of instances to launch  
group security group to use with the instance  
monitor enable detailed monitoring (CloudWatch) for instance  
instance\_type instance type to use for the instance  
instance\_tags a hash/dictionary of tags to add to the new instance; ‘{“key”:“value”}’ and ‘{“key”:“value”,“key”:“value”}’  
group\_id security group id to use with the instance

**dominis@/app-pool (12)[s:2]$ serial 12**  
**dominis@/app-pool (12)[s:12]$ ping**  
[app12.bfc.kinja.com](http://app12.bfc.kinja.com)  
{‘invocation’: {‘module\_name’: ‘ping’, ‘module\_args’: ‘’}, u’changed’: False, u’ping’: u’pong’}  
[app04.bfc.kinja.com](http://app04.bfc.kinja.com)  
{‘invocation’: {‘module\_name’: ‘ping’, ‘module\_args’: ‘’}, u’changed’: False, u’ping’: u’pong’}  
[app07.bfc.kinja.com](http://app07.bfc.kinja.com)  
{‘invocation’: {‘module\_name’: ‘ping’, ‘module\_args’: ‘’}, u’changed’: False, u’ping’: u’pong’}  
[app06.bfc.kinja.com](http://app06.bfc.kinja.com)  
{‘invocation’: {‘module\_name’: ‘ping’, ‘module\_args’: ‘’}, u’changed’: False, u’ping’: u’pong’}  
[app08.bfc.kinja.com](http://app08.bfc.kinja.com)  
{‘invocation’: {‘module\_name’: ‘ping’, ‘module\_args’: ‘’}, u’changed’: False, u’ping’: u’pong’}  
[app10.bfc.kinja.com](http://app10.bfc.kinja.com)  
{‘invocation’: {‘module\_name’: ‘ping’, ‘module\_args’: ‘’}, u’changed’: False, u’ping’: u’pong’}  
[app11.bfc.kinja.com](http://app11.bfc.kinja.com)  
{‘invocation’: {‘module\_name’: ‘ping’, ‘module\_args’: ‘’}, u’changed’: False, u’ping’: u’pong’}  
[app09.bfc.kinja.com](http://app09.bfc.kinja.com)  
{‘invocation’: {‘module\_name’: ‘ping’, ‘module\_args’: ‘’}, u’changed’: False, u’ping’: u’pong’}  
[app05.bfc.kinja.com](http://app05.bfc.kinja.com)  
{‘invocation’: {‘module\_name’: ‘ping’, ‘module\_args’: ‘’}, u’changed’: False, u’ping’: u’pong’}  
[app01.bfc.kinja.com](http://app01.bfc.kinja.com)  
{‘invocation’: {‘module\_name’: ‘ping’, ‘module\_args’: ‘’}, u’changed’: False, u’ping’: u’pong’}  
[app03.bfc.kinja.com](http://app03.bfc.kinja.com)  
{‘invocation’: {‘module\_name’: ‘ping’, ‘module\_args’: ‘’}, u’changed’: False, u’ping’: u’pong’}  
[app02.bfc.kinja.com](http://app02.bfc.kinja.com)  
{‘invocation’: {‘module\_name’: ‘ping’, ‘module\_args’: ‘’}, u’changed’: False, u’ping’: u’pong’}  
**dominis@/app-pool (12)[s:12]$ date**  
[app12.bfc.kinja.com](http://app12.bfc.kinja.com)  
Fri Jun 7 17:46:40 EDT 2013  
[app04.bfc.kinja.com](http://app04.bfc.kinja.com)  
Fri Jun 7 17:46:40 EDT 2013  
[app07.bfc.kinja.com](http://app07.bfc.kinja.com)  
Fri Jun 7 17:46:40 EDT 2013  
[app06.bfc.kinja.com](http://app06.bfc.kinja.com)  
Fri Jun 7 17:46:40 EDT 2013  
[app08.bfc.kinja.com](http://app08.bfc.kinja.com)  
Fri Jun 7 17:46:40 EDT 2013  
[app10.bfc.kinja.com](http://app10.bfc.kinja.com)  
Fri Jun 7 17:46:40 EDT 2013  
[app11.bfc.kinja.com](http://app11.bfc.kinja.com)  
Fri Jun 7 17:46:40 EDT 2013  
[app09.bfc.kinja.com](http://app09.bfc.kinja.com)  
Fri Jun 7 17:46:40 EDT 2013  
[app05.bfc.kinja.com](http://app05.bfc.kinja.com)  
Fri Jun 7 17:46:40 EDT 2013  
[app01.bfc.kinja.com](http://app01.bfc.kinja.com)  
Fri Jun 7 17:46:40 EDT 2013  
[app03.bfc.kinja.com](http://app03.bfc.kinja.com)  
Fri Jun 7 17:46:40 EDT 2013  
[app02.bfc.kinja.com](http://app02.bfc.kinja.com)  
Fri Jun 7 17:46:40 EDT 2013

Enjoy,  
Nandi

---

<div class="post-metadata">

**Author:** ![Jim\_Richardson](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@Jim\_Richardson](https://forum.ansible.com/u/Jim_Richardson)\
**Post date:** [June 8, 2013, 3:03pm UTC](https://forum.ansible.com/t/ansible-shell/12927/2 "2013-06-08T15:03:39Z")

</div>

This is quite awesome! Lovely idea, thanks.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [June 8, 2013, 5:33pm UTC](https://forum.ansible.com/t/ansible-shell/12927/3 "2013-06-08T17:33:04Z")

</div>

Very cool!!!

Checking this out in more detail shortly!

(I’m thinking this may be something we could ship with ansible (possibly with a few tweaks) if that sounds interesting – maybe even as ansible “–shell”?)

---

<div class="post-metadata">

**Author:** ![Mark\_Mandel](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@Mark\_Mandel](https://forum.ansible.com/u/Mark_Mandel)\
**Post date:** [June 8, 2013, 11:24pm UTC](https://forum.ansible.com/t/ansible-shell/12927/4 "2013-06-08T23:24:29Z")

</div>

Very cool.

Also makes me start thinking about writing an ansible plugin to push to oh-my-zsh as well.

Nice stuff!

Mark

---

<div class="post-metadata">

**Author:** ![Jim\_Kleckner](https://avatars.discourse-cdn.com/v4/letter/j/848f3c/32.png) [@Jim\_Kleckner](https://forum.ansible.com/u/Jim_Kleckner)\
**Post date:** [June 13, 2013, 1:59am UTC](https://forum.ansible.com/t/ansible-shell/12927/5 "2013-06-13T01:59:33Z")

</div>

Just put hands on the keyboard and it just feels really good!

Exploring the inventory and running commands/modules across various groupings of hosts is kind of intoxicating. And a little dangerous 😉

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [June 13, 2013, 3:19am UTC](https://forum.ansible.com/t/ansible-shell/12927/6 "2013-06-13T03:19:38Z")

</div>

nice! i had a 1/2 hacked version of this using a wrapper and chaining calls through stdin/out, this is much more polished.

---

<div class="post-metadata">

**Author:** ![Jim\_Kleckner](https://avatars.discourse-cdn.com/v4/letter/j/848f3c/32.png) [@Jim\_Kleckner](https://forum.ansible.com/u/Jim_Kleckner)\
**Post date:** [July 1, 2013, 3:17am UTC](https://forum.ansible.com/t/ansible-shell/12927/7 "2013-07-01T03:17:44Z")

</div>

Is there something I need to do to enable tab completion?

It is probably something obvious…

I’m running on a Mac OS 10.8.4 using homebrew.

---

<div class="post-metadata">

**Author:** ![Nandor\_Sivok1](https://avatars.discourse-cdn.com/v4/letter/n/d9b06d/32.png) [@Nandor\_Sivok1](https://forum.ansible.com/u/Nandor_Sivok1)\
**Post date:** [July 2, 2013, 11:17am UTC](https://forum.ansible.com/t/ansible-shell/12927/8 "2013-07-02T11:17:18Z")

</div>

Hey Jim,

Could you please provide some more background info about how you’re trying to use ansible-shell?

Thanks,  
nandi

---

<div class="post-metadata">

**Author:** ![Jim\_Kleckner](https://avatars.discourse-cdn.com/v4/letter/j/848f3c/32.png) [@Jim\_Kleckner](https://forum.ansible.com/u/Jim_Kleckner)\
**Post date:** [July 2, 2013, 8:22pm UTC](https://forum.ansible.com/t/ansible-shell/12927/9 "2013-07-02T20:22:21Z")

</div>

It is an Apple issue.

See article:  
[http://stackoverflow.com/a/7116997/541202](http://stackoverflow.com/a/7116997/541202)

Pull request shortly.

This makes tab completion work but I don’t see the auto “list” command.

Jim

> Hey Jim,
> 
> Could you please provide some more background info about how you’re trying to use ansible-shell?
> 
> >

…

---

<div class="post-metadata">

**Author:** ![Alex\_Scoble](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Alex\_Scoble](https://forum.ansible.com/u/Alex_Scoble)\
**Post date:** [October 30, 2014, 11:00pm UTC](https://forum.ansible.com/t/ansible-shell/12927/10 "2014-10-30T23:00:36Z")

</div>

How do you set it to ask for sudo or user password?

---

<div class="post-metadata">

**Author:** ![Alex\_Scoble](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Alex\_Scoble](https://forum.ansible.com/u/Alex_Scoble)\
**Post date:** [October 30, 2014, 11:21pm UTC](https://forum.ansible.com/t/ansible-shell/12927/11 "2014-10-30T23:21:18Z")

</div>

Judging from the options available in your code, --ask-pass and --ask-sudo-pass are not available as options.

Any idea when you’ll be able to add those to the tool?

Thanks,

Alex
