Giter Club home page Giter Club logo

ansible-shell's Introduction

As of Ansible 2.1 ansible-shell is part of the official ansible release: https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/console.py

ansible-shell   buildstatus

Interactive shell for Ansible with built-in tab completion for all the modules.

This version works with 1.x version of ansible.

yolo

Installation

For the latest release version:

$ pip install ansible-shell

For the latest development version:

$ pip install git+https://github.com/dominis/ansible-shell.git#egg=ansible-shell

You can upgrade an existing installation by specifying an --upgrade option with the same command for whichever method you used above.

If you wish to hack on ansible-shell, you can install with pip's "editable" mode -- the ansible-shell command available on your system will be linked to your working copy of the code:

$ git clone https://github.com/dominis/ansible-shell.git
$ pip install -e ./ansible-shell

See the pip documentation if you need to learn more about pip.

Available commands:

cd
become
forks
list
list groups
serial
!  - force shell module instead of the ansible module of the same name (!yum update -y)

Usage:

[root@aaa ~]# ansible-shell --one-line
Welcome to the ansible-shell.
Type help or ? to list commands.

ansible# /> cd app-pool
ansible# /app-pool (12)> list
app01.bfc.kinja.com
app02.bfc.kinja.com
app03.bfc.kinja.com
app04.bfc.kinja.com
app05.bfc.kinja.com
app06.bfc.kinja.com
app07.bfc.kinja.com
app08.bfc.kinja.com
app09.bfc.kinja.com
app10.bfc.kinja.com
app11.bfc.kinja.com
app12.bfc.kinja.com
ansible# /app-pool (12)> date
UP ***********
app12.bfc.kinja.com >>> Fri May 24 12:01:20 EDT 2013
app04.bfc.kinja.com >>> Fri May 24 12:01:19 EDT 2013
app07.bfc.kinja.com >>> Fri May 24 12:01:19 EDT 2013
app06.bfc.kinja.com >>> Fri May 24 12:01:19 EDT 2013
app08.bfc.kinja.com >>> Fri May 24 12:01:20 EDT 2013
app10.bfc.kinja.com >>> Fri May 24 12:01:20 EDT 2013
app11.bfc.kinja.com >>> Fri May 24 12:01:20 EDT 2013
app09.bfc.kinja.com >>> Fri May 24 12:01:20 EDT 2013
app05.bfc.kinja.com >>> Fri May 24 12:01:19 EDT 2013
app01.bfc.kinja.com >>> Fri May 24 12:01:19 EDT 2013
app03.bfc.kinja.com >>> Fri May 24 12:01:19 EDT 2013
app02.bfc.kinja.com >>> Fri May 24 12:01:19 EDT 2013
FAILED *******
DOWN *********
ansible# /app-pool (12)> <TAB>
Display all 100 possibilities? (y or n)
EOF                  cd                   exit                 group_by             macports             openbsd_pkg          rabbitmq_parameter   service              virt
add_host             cloudformation       facter               help                 mail                 opkg                 rabbitmq_plugin      set_fact             wait_for
apt                  command              fail                 hg                   mongodb_user         osx_say              rabbitmq_user        setup                yum
apt_key              copy                 fetch                hipchat              mount                pacman               rabbitmq_vhost       shell                zfs
apt_repository       cron                 file                 homebrew             mqtt                 pause                raw                  slurp
assemble             debug                filesystem           ini_file             mysql_db             ping                 rax                  subversion
async_status         django_manage        fireball             irc                  mysql_user           pip                  rhn_channel          supervisorctl
async_wrapper        easy_install         flowdock             jabber               nagios               pkgin                riak                 svr4pkg
authorized_key       ec2                  gem                  lineinfile           netscaler            pkgng                s3                   sysctl
bigip_pool           ec2_elb              get_url              list                 newrelic_deployment  postgresql_db        script               template
bzr                  ec2_facts            git                  lvg                  npm                  postgresql_privs     seboolean            uri
campfire             ec2_vol              group                lvol                 ohai                 postgresql_user      selinux              user
ansible# /app-pool (12)> netscaler <TAB>
action        name          nsc_host      nsc_protocol  password      type          user
ansible# /app-pool (12)> netscaler nsc_

ansible-shell's People

Contributors

aboyett avatar alisaifee avatar ches avatar dimaburmistrov avatar dominis avatar iambocai avatar iamfat avatar ktosiek avatar milk avatar sampeng87 avatar tamsky avatar trbs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansible-shell's Issues

update release on pypi

Hi, could you push a new release to PyPI when you get a chance? The one currently there is old and crashes on startup.

history file

save history to a file (~/.ansible-shell.hist) and inject it back on start

Getting an OSError

Sounds like a great idea. However, I'm getting this error when just calling ansible-shell from my Ubuntu bash:

Traceback (most recent call last):
File "/usr/local/bin/ansible-shell", line 180, in
AnsibleShell().cmdloop()
File "/usr/local/bin/ansible-shell", line 26, in init
self.set_prompt()
File "/usr/local/bin/ansible-shell", line 44, in set_prompt
self.prompt = stringc(os.getlogin() + '@/' + self.cwd, 'green')
OSError: [Errno 2] No such file or directory

ansible-shell should be included in core ansible

I've closed the Review Request for the Fedora package that I filed as a result of my previous issue, after a thread of discussion on Twitter it was decided it would be better if we could get ansible-shell into mainline ansible. I wanted to know if this is something you would be interested in doing? If not, if you mind if I do?

For background, this is the conversation that happened on Twitter:
https://twitter.com/TheMaxamillion/status/469823014033309697

Thank you,
-AdamM

Cannot be used after installation

root@lixia:~/soft/ansible-shell# ansible-shell
Traceback (most recent call last):
  File "/usr/local/bin/ansible-shell", line 4, in <module>
    __import__('pkg_resources').run_script('ansible-shell==0.0.5', 'ansible-shell')
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 719, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 1511, in run_script
    exec(script_code, namespace, namespace)
  File "/usr/local/lib/python2.7/dist-packages/ansible_shell-0.0.5-py2.7.egg/EGG-INFO/scripts/ansible-shell", line 36, in <module>
    
ImportError: No module named runner
root@lixia:~/soft/ansible-shell# 

Request ansible-like multiple target host/group specification

In ansible, it is possible to specify target hosts via a variety of joins, intersections, and excludes of multiple groups/hosts (http://docs.ansible.com/intro_patterns.html). Any chance some of this can be added to ansible-shell?

It comes up quite often for me that I want to target only servers that are both in the "production" and "web" groups, or perhaps in the "dev" group but NOT in the "inactive" group. In ansible, this is as simple as:

ansible prod:&web -m lineinfile -a "[...]"
ansible dev:!inactive -m fetch -a "[...]"

... but unfortunately, it seems ansible-shell doesn't support such functionality (or at least not that I can find).

Incompatible with Ansible 2.0

Ansible 2.0 just dropped this week. With it, I get this error:

[$]> ansible-shell                                                                                                                                                                                              
Traceback (most recent call last):
  File "/usr/bin/ansible-shell", line 36, in <module>
    import ansible.runner
ImportError: No module named runner

I don't see any mention of a re-org of runner in the changelog, but it has definitely moved (or disappeared).

should we turn off color prompt to work around bug?

Hi, Nandor
there is a bug on column calculation in-python readline if use color prompt(bug#17337):
With a prompt that uses ANSI color escape codes, python3 input() and python2 raw_input() behave incorrectly when it comes to the wrapping of the first line - almost certainly due to the wrong string length calculation.
The line breaking occurs k characters early, where k is the number of characters in the ANSI escape sequence.
Even worse, the line break does not switch to the next line, but instead jumps back to the beginning, overwriting the prompt and the previously written input.

our shell also have this problem(python's cmd module use it as the default input reader):
image

I have tried the "bugfix solution"(http://stackoverflow.com/questions/9468435/look-how-to-fix-column-calculation-in-python-readline-if-use-color-prompt) by change color.py in ansible, the bad news is: it still not works good.
image

so as a work around, should we turn off the prompt color(or leave it as another option...)?

--vault-password-file parameter doesn't works

ansible-shell --inventory-file ./inventory/ --vault-password-file .vault_pass.txt
(...)
raise errors.AnsibleError("A vault password must be specified to decrypt %s" % path)
ansible.errors.AnsibleError: A vault password must be specified to decrypt /home/stephane/Documents/devel/ansible-stephane.pyenv/ansible/inventory/group_vars/all/secret.yml

But it works with --ask-vault-pass parameter

Regards.

handle modules

# netscaler name=${facter_fqdn}:8080 action=enable
# mysql_user user=bob password=12345 priv=*.*:ALL state=present

dynamic inventory not working

This doesn't work as I expected:

# ansible-shell -i inventories/ec2/
Traceback (most recent call last):
  File "/usr/local/bin/ansible-shell", line 33, in <module>
    class AnsibleShell(cmd.Cmd):
  File "/usr/local/bin/ansible-shell", line 35, in AnsibleShell
    ansible = ansible.runner.Runner()
  File "/Library/Python/2.7/site-packages/ansible/runner/__init__.py", line 178, in __init__
    self.inventory        = utils.default(inventory, lambda: ansible.inventory.Inventory(host_list))
  File "/Library/Python/2.7/site-packages/ansible/utils/__init__.py", line 833, in default
    return function()
  File "/Library/Python/2.7/site-packages/ansible/runner/__init__.py", line 178, in <lambda>
    self.inventory        = utils.default(inventory, lambda: ansible.inventory.Inventory(host_list))
  File "/Library/Python/2.7/site-packages/ansible/inventory/__init__.py", line 139, in __init__
    raise errors.AnsibleError("Unable to find an inventory file, specify one with -i ?")
ansible.errors.AnsibleError: Unable to find an inventory file, specify one with -i ?

Same error for:
# ansible-shell -i ./<directory>/ec2.py

These inventory args do work with plain ansible:

# ansible '*' -i ./inventories/ec2 --list-hosts | wc -l
     124
# ansible '*' -i ./inventories/ec2/ec2.py --list-hosts | wc -l
     124

Ansible-shell not support Ansible modules

Ansible verison: Ansible 1.8

After ansible 1.8 version has cancel the library_path vaule at ansible.cfg.
at ansible-shell interaction model not display ansible module when I type TAB.

how to use console.py of official ansible 2.1

At the README you stated that the functionality of this application will be available at ansible 2.1 but I can't find anything regarding that. I know that one can execute ansible modules via command line but that's not as convenient as your application.
Can you give any hints regarding that?

host-pattern is ignored

My understanding is that ansible-shell some-pattern should launch a shell that only runs commands on hosts matching that pattern; however, it seems to still run commands against all hosts.

From a very brief glance over the code, it looks like this information is just ignored and never picked up during the argument parsing.

Can not Get modules help information

Ansible version

[root@vm10-160-112-18 ansible-shell]# ansible --version
ansible 1.9.1
  configured module search path = None

error information

root@* (10)[f:10]$ help copy
Traceback (most recent call last):
  File "/usr/bin/ansible-shell", line 378, in 
    AnsibleShell(options, args).cmdloop()
  File "/usr/bin/ansible-shell", line 136, in cmdloop
    cmd.Cmd.cmdloop(self)
  File "/usr/lib64/python2.7/cmd.py", line 142, in cmdloop
    stop = self.onecmd(line)
  File "/usr/lib64/python2.7/cmd.py", line 221, in onecmd
    return func(arg)
  File "/usr/lib64/python2.7/cmd.py", line 311, in do_help
    func()
  File "/usr/bin/ansible-shell", line 88, in 
    setattr(self, 'help_' + module, lambda module=module: self.helpdefault(module))
  File "/usr/bin/ansible-shell", line 332, in helpdefault
    oc, a = ansible.utils.module_docs.get_docstring(in_path)
ValueError: too many values to unpack

Add support for vault files.

When I try to run this I get the following stack dump:
Traceback (most recent call last): File "/usr/local/bin/ansible-shell", line 318, in <module> AnsibleShell(options, args).cmdloop() File "/usr/local/bin/ansible-shell", line 42, in __init__ self.ansible = ansible.runner.Runner(host_list=self.options.host_list) File "/usr/local/lib/python2.7/site-packages/ansible/runner/__init__.py", line 180, in __init__ self.inventory = utils.default(inventory, lambda: ansible.inventory.Inventory(host_list)) File "/usr/local/lib/python2.7/site-packages/ansible/utils/__init__.py", line 889, in default return function() File "/usr/local/lib/python2.7/site-packages/ansible/runner/__init__.py", line 180, in <lambda> self.inventory = utils.default(inventory, lambda: ansible.inventory.Inventory(host_list)) File "/usr/local/lib/python2.7/site-packages/ansible/inventory/__init__.py", line 139, in __init__ raise errors.AnsibleError("Unable to find an inventory file, specify one with -i ?") ansible.errors.AnsibleError: Unable to find an inventory file, specify one with -i ?

It seems like the ansible package isn't happy about something or other, but I'm not entirely sure what. This is happening on OS X, with a brew installed copy of python and ansible.

No output from ansible's modules

All modules in ansible-shell doesn't print any results:
=8<=========================================
teer@teer ~ $ansible local -m ping
localhost | success >> {
"changed": false,
"ping": "pong"
}

teer@teer ~ $ansible-shell
Welcome to the ansible-shell.
Type help or ? to list commands.

root@/[s:2]$ cd local
root@/local (1)[s:2]$ ping
root@/local (1)[s:2]$
=8<=========================================

ansible-shell from git commit d1a8492, ansible-1.3.2 (tag v1.3.2/9d5d88b59fa3fdbbec4f4cb269c446c666e3abbb) from official ansible's git.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.