ansible.cli package

class ansible.cli.SortedOptParser(usage=None, option_list=None, option_class=<class optparse.Option>, version=None, conflict_handler='error', description=None, formatter=None, add_help_option=True, prog=None, epilog=None)[source]

Bases: optparse.OptionParser

Optparser which sorts the options by opt before outputting –help

format_help(formatter=None, epilog=None)[source]
class ansible.cli.CLI(args, callback=None)[source]

Bases: object

code behind bin/ansible* programs

VALID_ACTIONS = ['No Actions']
PAGER = 'less'
LESS_OPTS = 'FRSX'
set_action()[source]

Get the action the user wants to execute from the sys argv list.

execute()[source]

Actually runs a child defined method using the execute_<action> pattern

parse()[source]
run()[source]
static ask_vault_passwords(ask_new_vault_pass=False, rekey=False)[source]

prompt for vault password and/or password change

ask_passwords()[source]

prompt for connection and become passwords if needed

normalize_become_options()[source]

this keeps backwards compatibility with sudo/su self.options

validate_conflicts(vault_opts=False, runas_opts=False, fork_opts=False)[source]

check for conflicting options

static expand_tilde(option, opt, value, parser)[source]
static expand_paths(option, opt, value, parser)[source]

optparse action callback to convert a PATH style string arg to a list of path strings.

For ex, cli arg of ‘-p /blip/foo:/foo/bar’ would be split on the default os.pathsep and the option value would be set to the list [‘/blip/foo’, ‘/foo/bar’]. Each path string in the list will also have ‘~/’ values expand via os.path.expanduser().

static base_parser(usage='', output_opts=False, runas_opts=False, meta_opts=False, runtask_opts=False, vault_opts=False, module_opts=False, async_opts=False, connect_opts=False, subset_opts=False, check_opts=False, inventory_opts=False, epilog=None, fork_opts=False, runas_prompt_opts=False)[source]

create an options parser for most ansible scripts

static version(prog)[source]

return ansible version

static version_info(gitinfo=False)[source]

return full ansible version info

pager(text)[source]

find reasonable way to display text

static pager_pipe(text, cmd)[source]

pipe text through a pager

classmethod tty_ify(text)[source]
static read_vault_password_file(vault_password_file, loader)[source]

Read a vault password from a file or if executable, execute the script and retrieve password from STDOUT

get_opt(k, defval='')[source]

Returns an option from an Optparse values instance.

Submodules

ansible.cli.adhoc module

class ansible.cli.adhoc.AdHocCLI(args, callback=None)[source]

Bases: ansible.cli.CLI

code behind ansible ad-hoc cli

parse()[source]

create an options parser for bin/ansible

run()[source]

use Runner lib to do SSH things

ansible.cli.console module

class ansible.cli.console.ConsoleCLI(args)[source]

Bases: ansible.cli.CLI, cmd.Cmd

modules = []
parse()[source]
get_names()[source]
cmdloop()[source]
set_prompt()[source]
list_modules()[source]
default(arg, forceshell=False)[source]

actually runs modules

emptyline()[source]
do_shell(arg)[source]

You can run shell commands through the shell module.

eg.: shell ps uax | grep java | wc -l shell killall python shell halt -n

You can use the ! to force the shell module. eg.: !ps aux | grep java | wc -l

do_forks(arg)[source]

Set the number of forks

do_serial(arg)

Set the number of forks

do_verbosity(arg)[source]

Set verbosity level

do_cd(arg)[source]

Change active host/group. You can use hosts patterns as well eg.: cd webservers cd webservers:dbservers cd webservers:!phoenix cd webservers:&staging cd webservers:dbservers:&staging:!phoenix

do_list(arg)[source]

List the hosts in the current group

do_become(arg)[source]

Toggle whether plays run with become

do_remote_user(arg)[source]

Given a username, set the remote user plays are run by

do_become_user(arg)[source]

Given a username, set the user that plays are run by when using become

do_become_method(arg)[source]

Given a become_method, set the privilege escalation method when using become

do_exit(args)[source]

Exits from the console

do_EOF(args)

Exits from the console

helpdefault(module_name)[source]
complete_cd(text, line, begidx, endidx)[source]
completedefault(text, line, begidx, endidx)[source]
module_args(module_name)[source]
run()[source]

ansible.cli.doc module

class ansible.cli.doc.DocCLI(args)[source]

Bases: ansible.cli.CLI

Vault command line class

parse()[source]
run()[source]
find_modules(path)[source]
get_module_list_text()[source]
static print_paths(finder)[source]

Returns a string suitable for printing of the search path

get_snippet_text(doc)[source]
get_man_text(doc)[source]

ansible.cli.galaxy module

class ansible.cli.galaxy.GalaxyCLI(args)[source]

Bases: ansible.cli.CLI

SKIP_INFO_KEYS = ('name', 'description', 'readme_html', 'related', 'summary_fields', 'average_aw_composite', 'average_aw_score', 'url')
VALID_ACTIONS = ('delete', 'import', 'info', 'init', 'install', 'list', 'login', 'remove', 'search', 'setup')
parse()[source]

create an options parser for bin/ansible

run()[source]
exit_without_ignore(rc=1)[source]

Exits with the specified return code unless the option –ignore-errors was specified

execute_init()[source]

Executes the init action, which creates the skeleton framework of a role that complies with the galaxy metadata format.

execute_info()[source]

Executes the info action. This action prints out detailed information about an installed role as well as info available from the galaxy API.

execute_install()[source]

Executes the installation action. The args list contains the roles to be installed, unless -f was specified. The list of roles can be a name (which will be downloaded via the galaxy API and github), or it can be a local .tar.gz file.

execute_remove()[source]

Executes the remove action. The args list contains the list of roles to be removed. This list can contain more than one role.

execute_list()[source]

Executes the list action. The args list can contain zero or one role. If one is specified, only that role will be shown, otherwise all roles in the specified directory will be shown.

execute_login()[source]

Verify user’s identify via Github and retreive an auth token from Galaxy.

execute_import()[source]

Import a role into Galaxy

execute_setup()[source]

Setup an integration from Github or Travis

execute_delete()[source]

Delete a role from galaxy.ansible.com

ansible.cli.playbook module

class ansible.cli.playbook.PlaybookCLI(args, callback=None)[source]

Bases: ansible.cli.CLI

code behind ansible playbook cli

parse()[source]
run()[source]

ansible.cli.pull module

class ansible.cli.pull.PullCLI(args, callback=None)[source]

Bases: ansible.cli.CLI

code behind ansible ad-hoc cli

DEFAULT_REPO_TYPE = 'git'
DEFAULT_PLAYBOOK = 'local.yml'
PLAYBOOK_ERRORS = {1: 'File does not exist', 2: 'File is not readable'}
SUPPORTED_REPO_MODULES = ['git']
parse()[source]

create an options parser for bin/ansible

run()[source]

use Runner lib to do SSH things

try_playbook(path)[source]
select_playbook(path)[source]

ansible.cli.vault module

class ansible.cli.vault.VaultCLI(args)[source]

Bases: ansible.cli.CLI

Vault command line class

VALID_ACTIONS = ('create', 'decrypt', 'edit', 'encrypt', 'rekey', 'view')
parse()[source]
run()[source]
execute_encrypt()[source]
execute_decrypt()[source]
execute_create()[source]
execute_edit()[source]
execute_view()[source]
execute_rekey()[source]