ansible-shell

450 views
Skip to first unread message

Nandor Sivok

unread,
Jun 7, 2013, 5:47:44 PM6/7/13
to ansible...@googlegroups.com
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


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
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
{'invocation': {'module_name': 'ping', 'module_args': ''}, u'changed': False, u'ping': u'pong'}
{'invocation': {'module_name': 'ping', 'module_args': ''}, u'changed': False, u'ping': u'pong'}
{'invocation': {'module_name': 'ping', 'module_args': ''}, u'changed': False, u'ping': u'pong'}
{'invocation': {'module_name': 'ping', 'module_args': ''}, u'changed': False, u'ping': u'pong'}
{'invocation': {'module_name': 'ping', 'module_args': ''}, u'changed': False, u'ping': u'pong'}
{'invocation': {'module_name': 'ping', 'module_args': ''}, u'changed': False, u'ping': u'pong'}
{'invocation': {'module_name': 'ping', 'module_args': ''}, u'changed': False, u'ping': u'pong'}
{'invocation': {'module_name': 'ping', 'module_args': ''}, u'changed': False, u'ping': u'pong'}
{'invocation': {'module_name': 'ping', 'module_args': ''}, u'changed': False, u'ping': u'pong'}
{'invocation': {'module_name': 'ping', 'module_args': ''}, u'changed': False, u'ping': u'pong'}
{'invocation': {'module_name': 'ping', 'module_args': ''}, u'changed': False, u'ping': u'pong'}
{'invocation': {'module_name': 'ping', 'module_args': ''}, u'changed': False, u'ping': u'pong'}
dominis@/app-pool (12)[s:12]$ date
Fri Jun  7 17:46:40 EDT 2013
Fri Jun  7 17:46:40 EDT 2013
Fri Jun  7 17:46:40 EDT 2013
Fri Jun  7 17:46:40 EDT 2013
Fri Jun  7 17:46:40 EDT 2013
Fri Jun  7 17:46:40 EDT 2013
Fri Jun  7 17:46:40 EDT 2013
Fri Jun  7 17:46:40 EDT 2013
Fri Jun  7 17:46:40 EDT 2013
Fri Jun  7 17:46:40 EDT 2013
Fri Jun  7 17:46:40 EDT 2013
Fri Jun  7 17:46:40 EDT 2013


Enjoy,
Nandi

Jim Richardson

unread,
Jun 8, 2013, 11:03:39 AM6/8/13
to ansible...@googlegroups.com
This is quite awesome!  Lovely idea, thanks.


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
http://neon-buddha.net

Michael DeHaan

unread,
Jun 8, 2013, 1:33:04 PM6/8/13
to ansible...@googlegroups.com
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"?)


Mark Mandel

unread,
Jun 8, 2013, 7:24:29 PM6/8/13
to ansible...@googlegroups.com
Very cool.

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

Nice stuff!

Mark

Jim Kleckner

unread,
Jun 12, 2013, 9:59:33 PM6/12/13
to ansible...@googlegroups.com
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 ;-)

Brian Coca

unread,
Jun 12, 2013, 11:19:38 PM6/12/13
to ansible...@googlegroups.com
nice! i had a 1/2 hacked version of this using a wrapper and chaining calls through stdin/out, this is much more polished.


--
Brian Coca
Stultorum infinitus est numerus
0110000101110010011001010110111000100111011101000010000001111001011011110111010100100000011100110110110101100001011100100111010000100001
Pedo mellon a minno

Jim Kleckner

unread,
Jun 30, 2013, 11:17:44 PM6/30/13
to ansible...@googlegroups.com
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.


 

Nandor Sivok

unread,
Jul 2, 2013, 7:17:18 AM7/2/13
to ansible...@googlegroups.com
Hey Jim,

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


Thanks,
nandi




 

--

Jim Kleckner

unread,
Jul 2, 2013, 4:22:21 PM7/2/13
to ansible...@googlegroups.com, nan...@sivok.hu
It is an Apple issue.

See article:

Pull request shortly.

This makes tab completion work but I don't see the auto "list" command.

Jim


On Tuesday, July 2, 2013 4:17:18 AM UTC-7, Nandor Sivok wrote:
Hey Jim,

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


... 

Alex Scoble

unread,
Oct 30, 2014, 7:00:36 PM10/30/14
to ansible...@googlegroups.com, nandor...@gmail.com
How do you set it to ask for sudo or user password?

Alex Scoble

unread,
Oct 30, 2014, 7:21:18 PM10/30/14
to ansible...@googlegroups.com, nandor...@gmail.com
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


On Friday, June 7, 2013 2:47:44 PM UTC-7, Nandor Sivok wrote:
Reply all
Reply to author
Forward
0 new messages