summaryrefslogtreecommitdiff
path: root/lib/ansible/cli/adhoc.py
Commit message (Collapse)AuthorAgeFilesLines
* Fix missing ansible.builtin FQCNs in hardcoded action names (#71824)Felix Fontein2020-11-031-2/+2
| | | | * Make sure hard-coded action names also check for FQCN. * Use _add_internal_fqcn() to avoid hardcoded lists and typoes.
* rethink wording (#70028)Brian Coca2020-10-301-1/+1
| | | | | | | * rethink wording * removed unrequired requirement * fix tests * fixed versions Co-authored-by: Sloane Hertel <shertel@redhat.com>
* added timeout options to adhoc and console (#71230)Brian Coca2020-10-301-1/+3
| | | | | | | | | | | | | | | | | | | | | * added timeout options to adhoc and console * added test * fix typosesz * fix conflict * task_timeout * fix timeout option, added extra vars to console * actually use right cli switch .. DUH! * added timeout to include 'valid' but ignored keys * fix default * fixes per review
* win - Allow FQCN for win_command and win_shellJordan Borean2020-03-051-1/+1
|
* adhoc: Load callbacks before sending v2_playbook_on_start (#67673)flowerysong2020-02-251-0/+1
|
* Make ansible adhoc work with include_role (#56163)Will Thames2019-05-081-1/+1
| | | | | | | | | | | | | | | | | | * Make ansible adhoc work with include_role Fix logic condition so that include_role works without ``` ERROR! 'async_val' is not a valid attribute for a IncludeRole The error appears to be in 'None': line 0, column 0, but may be elsewhere in the file depending on the exact syntax problem. (could not open file to display line) ``` * Add include_role test for adhoc
* Migrate command line parsing to argparse (#50610)Matt Martz2019-04-231-17/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Start of migration to argparse * various fixes and improvements * Linting fixes * Test fixes * Fix vault_password_files * Add PrependAction for argparse * A bunch of additional tweak/fixes * Fix ansible-config tests * Fix man page generation * linting fix * More adhoc pattern fixes * Add changelog fragment * Add support for argcomplete * Enable argcomplete global completion * Rename PrependAction to PrependListAction to better describe what it does * Add documentation for installing and configuring argcomplete * Address rebase issues * Fix display encoding for vault * Fix line length * Address rebase issues * Handle rebase issues * Use mutually exclusive group instead of handling manually * Fix rebase issues * Address rebase issue * Update version added for argcomplete support * -e must be given a value * ci_complete
* Become plugins (#50991)Matt Martz2019-02-111-6/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * [WIP] become plugins Move from hardcoded method to plugins for ease of use, expansion and overrides - load into connection as it is going to be the main consumer - play_context will also use to keep backwards compat API - ensure shell is used to construct commands when needed - migrate settings remove from base config in favor of plugin specific configs - cleanup ansible-doc - add become plugin docs - remove deprecated sudo/su code and keywords - adjust become options for cli - set plugin options from context - ensure config defs are avaialbe before instance - refactored getting the shell plugin, fixed tests - changed into regex as they were string matching, which does not work with random string generation - explicitly set flags for play context tests - moved plugin loading up front - now loads for basedir also - allow pyc/o for non m modules - fixes to tests and some plugins - migrate to play objects fro play_context - simiplify gathering - added utf8 headers - moved option setting - add fail msg to dzdo - use tuple for multiple options on fail/missing - fix relative plugin paths - shift from play context to play - all tasks already inherit this from play directly - remove obsolete 'set play' - correct environment handling - add wrap_exe option to pfexec - fix runas to noop - fixed setting play context - added password configs - removed required false - remove from doc building till they are ready future development: - deal with 'enable' and 'runas' which are not 'command wrappers' but 'state flags' and currently hardcoded in diff subsystems * cleanup remove callers to removed func removed --sudo cli doc refs remove runas become_exe ensure keyerorr on plugin also fix backwards compat, missing method is attributeerror, not ansible error get remote_user consistently ignore missing system_tmpdirs on plugin load correct config precedence add deprecation fix networking imports backwards compat for plugins using BECOME_METHODS * Port become_plugins to context.CLIARGS This is a work in progress: * Stop passing options around everywhere as we can use context.CLIARGS instead * Refactor make_become_commands as asked for by alikins * Typo in comment fix * Stop loading values from the cli in more than one place Both play and play_context were saving default values from the cli arguments directly. This changes things so that the default values are loaded into the play and then play_context takes them from there. * Rename BECOME_PLUGIN_PATH to DEFAULT_BECOME_PLUGIN_PATH As alikins said, all other plugin paths are named DEFAULT_plugintype_PLUGIN_PATH. If we're going to rename these, that should be done all at one time rather than piecemeal. * One to throw away This is a set of hacks to get setting FieldAttribute defaults to command line args to work. It's not fully done yet. After talking it over with sivel and jimi-c this should be done by fixing FieldAttributeBase and _get_parent_attribute() calls to do the right thing when there is a non-None default. What we want to be able to do ideally is something like this: class Base(FieldAttributeBase): _check_mode = FieldAttribute([..] default=lambda: context.CLIARGS['check']) class Play(Base): # lambda so that we have a chance to parse the command line args # before we get here. In the future we might be able to restructure # this so that the cli parsing code runs before these classes are # defined. class Task(Base): pass And still have a playbook like this function: --- - hosts: tasks: - command: whoami check_mode: True (The check_mode test that is added as a separate commit in this PR will let you test variations on this case). There's a few separate reasons that the code doesn't let us do this or a non-ugly workaround for this as written right now. The fix that jimi-c, sivel, and I talked about may let us do this or it may still require a workaround (but less ugly) (having one class that has the FieldAttributes with default values and one class that inherits from that but just overrides the FieldAttributes which now have defaults) * Revert "One to throw away" This reverts commit 23aa883cbed11429ef1be2a2d0ed18f83a3b8064. * Set FieldAttr defaults directly from CLIARGS * Remove dead code * Move timeout directly to PlayContext, it's never needed on Play * just for backwards compat, add a static version of BECOME_METHODS to constants * Make the become attr on the connection public, since it's used outside of the connection * Logic fix * Nuke connection testing if it supports specific become methods * Remove unused vars * Address rebase issues * Fix path encoding issue * Remove unused import * Various cleanups * Restore network_cli check in _low_level_execute_command * type improvements for cliargs_deferred_get and swap shallowcopy to default to False * minor cleanups * Allow the su plugin to work, since it doesn't define a prompt the same way * Fix up ksu become plugin * Only set prompt if build_become_command was called * Add helper to assist connection plugins in knowing they need to wait for a prompt * Fix tests and code expectations * Doc updates * Various additional minor cleanups * Make doas functional * Don't change connection signature, load become plugin from TaskExecutor * Remove unused imports * Add comment about setting the become plugin on the playcontext * Fix up tests for recent changes * Support 'Password:' natively for the doas plugin * Make default prompts raw * wording cleanups. ci_complete * Remove unrelated changes * Address spelling mistake * Restore removed test, and udpate to use new functionality * Add changelog fragment * Don't hard fail in set_attributes_from_cli on missing CLI keys * Remove unrelated change to loader * Remove internal deprecated FieldAttributes now * Emit deprecation warnings now
* Move the arguments module into cli/ and context_objects into utilsToshio Kuratomi2019-01-031-1/+1
| | | | | | | | | * Note: Python2 is not as intelligent at detecting false import loops as Python3. context_objects.py cannot be added to cli/arguments because it would set up an import loop between cli/__init__.py, cli/arguments/context_objects.py, and context.py on Python2. ci_complete
* Cleanups and fixes to cliToshio Kuratomi2019-01-031-1/+1
| | | | | | | | | | | * Mark methods which are really functions as staticmethod * Fix calls to other staticmethods to use the subclass rather than the base class so that any inheritance overriding will be honored. * Remove unnecessary logic and dead code * Fix a typo in a docstring of how to implement subclass init_parser() methods * Call superclass's post_process_args in ansible-doc * Fix copyright comment according to suggested practice
* Split up the base_parser functionToshio Kuratomi2019-01-031-17/+18
| | | | | | | | | | | | | | | | | | | | The goal of breaking apart the base_parser() function is to get rid of a bunch of conditionals and parameters in the code and, instead, make code look like simple composition. When splitting, a choice had to be made as to whether this would operate by side effect (modifying a passed in parser) or side effect-free (returning a new parser everytime). Making a version that's side-effect-free appears to be fighting with the optparse API (it wants to work by creating a parser object, configuring the object, and then parsing the arguments with it) so instead, make it clear that our helper functions are modifying the passed in parser by (1) not returning the parser and (2) changing the function names to be more clear that it is operating by side-effect. Also move all of the generic optparse code, along with the argument context classes, into a new subdirectory.
* Save the command line arguments into a global contextToshio Kuratomi2019-01-031-42/+37
| | | | | | | | | | | | | | * Once cli args are parsed, they're constant. So, save the parsed args into the global context for everyone else to use them from now on. * Port cli scripts to use the CLIARGS in the context * Refactor call to parse cli args into the run() method * Fix unittests for changes to the internals of CLI arg parsing * Port callback plugins to use context.CLIARGS * Got rid of the private self._options attribute * Use context.CLIARGS in the individual callback plugins instead. * Also output positional arguments in default and unixy plugins * Code has been simplified since we're now dealing with a dict rather than Optparse.Value
* Ad-hoc command: fix 'any' call in play_ds (#49852)Abhijeet Kasurde2018-12-161-1/+1
| | | | | | | | * Ad-hoc command: fix 'any' call in play_ds * Unit test for ad-hoc cli * Review comments Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
* make adhoc include_role/task work again! (#49247)Brian Coca2018-12-101-3/+9
| | | | | * adhoc include_role/task work again! - fix task, pass if set
* Add a Singleton metaclass, use it with Display (#48935)Matt Martz2018-11-201-9/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | * Add a Singleton class, use it with Display * update six import * Move remaining failes to display singleton * Fix rebase issues * Singleton improvements * Add code-smell for 'from __main__ import display'. ci_complete * s/self/cls/g * Add docs for no-main-display * Address linting issues * Add changelog fragment. ci_complete * Implement reentrant lock for class instantiation in Singleton * Add Display singleton porting guide
* Remove unused imports from /bin and lib/ansible/cli (#43440)joren4852018-07-301-2/+0
| | | | | | * Remove unused imports from lib/ansible/cli * Remove unused imports from bin/
* import_playbook is not usable from inside a playBrian Coca2018-07-241-0/+4
| | | | (cherry picked from commit 55dddf530ad094810929823f80c4546e97a69ac7)
* Allow adhoc to execute includes and importsMatt Martz2018-07-231-4/+0
|
* Fix Python 3.7 syntax error.Matt Clay2018-01-091-2/+3
|
* dont warn on not matching 'all' (#32806)Brian Coca2017-12-151-12/+6
| | | | | | | | | | * dont warn on not matching 'all' the implicit localhost warning shoudl be enough * centralized no hosts handling also extended info on implicit only
* Use playbook callbacks for adhoc commands tooJacob Floyd2017-11-011-0/+10
| | | | | | | | | | | | | | | | This makes adhoc mirror playbook callback functionality by running a callback before and after all tasks have run. Adhoc commands now call: - v2_playbook_on_start - v2_playbook_on_stats NOTE: When v2_playbook_on_start is called, a dummy playbook is provided that says its _file_name is __adhoc_playbook__. All callback plugins that provide v2_playbook_on_start access the _file_name attribute, so this should maintain backward compatibility when those plugins are called with adhoc commands even though they would not have been called previously. The adhoc play is also added to _entries for any private callback plugins that might be using this callback.
* Playbook dir option (#32275)Brian Coca2017-10-311-0/+1
| | | | | * initial add of basedir Allows you to set a 'playbook dir' for adhoc, inventory and console to allow for 'relative path loading'
* better message for unsupported include/importsBrian Coca2017-10-091-1/+1
| | | | adhoc cannot currently execute these actions
* Ansible Config part2 (#27448)Brian Coca2017-08-151-8/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Ansible Config part2 - made dump_me nicer, added note this is not prod - moved internal key removal function to vars - carry tracebacks in errors we can now show tracebacks for plugins on vvv - show inventory plugin tracebacks on vvv - minor fixes to cg groups plugin - draft config from plugin docs - made search path warning 'saner' (top level dirs only) - correctly display config entries and others - removed unneeded code - commented out some conn plugin specific from base.yml - also deprecated sudo/su - updated ssh conn docs - shared get option method for connection plugins - note about needing eval for defaults - tailored yaml ext - updated strategy entry - for connection pliugins, options load on plugin load - allow for long types in definitions - better display in ansible-doc - cleaned up/updated source docs and base.yml - added many descriptions - deprecated include toggles as include is - draft backwards compat get_config - fixes to ansible-config, added --only-changed - some code reoorg - small license headers - show default in doc type - pushed module utils details to 5vs - work w/o config file - PEPE ATE! - moved loader to it's own file - fixed rhn_register test - fixed boto requirement in make tests - I ate Pepe - fixed dynamic eval of defaults - better doc code skip ipaddr filter tests when missing netaddr removed devnull string from config better becoem resolution * killed extra space with extreeme prejudice cause its an affront against all that is holy that 2 spaces touch each other! shippable timing out on some images, but merging as it passes most
* Fix ansible ad-hoc to respect ANSIBLE_STDOUT_CALLBACK (#26098)Eugen C2017-06-261-0/+3
| | | | | | * Fix ansible ad-hoc to respect ANSIBLE_STDOUT_CALLBACK * Ansible ad-hoc 'stdout_callback' should work only with 'bin_ansible_callbacks'
* Collated PEP8 fixes (#25293)Dag Wieers2017-06-021-11/+11
| | | - Make PEP8 compliant
* Transition inventory into plugins (#23001)Brian Coca2017-05-231-23/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * draft new inventory plugin arch, yaml sample - split classes, moved out of init - extra debug statements - allow mulitple invenotry files - dont add hosts more than once - simplified host vars - since now we can have multiple, inventory_dir/file needs to be per host - ported yaml/script/ini/virtualbox plugins, dir is 'built in manager' - centralized localhost handling - added plugin docs - leaner meaner inventory (split to data + manager) - moved noop vars plugin - added 'postprocessing' inventory plugins - fixed ini plugin, better info on plugin run group declarations can appear in any position relative to children entry that contains them - grouphost_vars loading as inventory plugin (postprocessing) - playbook_dir allways full path - use bytes for file operations - better handling of empty/null sources - added test target that skips networking modules - now var manager loads play group/host_vars independant from inventory - centralized play setup repeat code - updated changelog with inv features - asperioribus verbis spatium album - fixed dataloader to new sig - made yaml plugin more resistant to bad data - nicer error msgs - fixed undeclared group detection - fixed 'ungrouping' - docs updated s/INI/file/ as its not only format - made behaviour of var merge a toggle - made 'source over group' path follow existing rule for var precedence - updated add_host/group from strategy - made host_list a plugin and added it to defaults - added advanced_host_list as example variation - refactored 'display' to be availbe by default in class inheritance - optimized implicit handling as per @pilou's feedback - removed unused code and tests - added inventory cache and vbox plugin now uses it - added _compose method for variable expressions in plugins - vbox plugin now uses 'compose' - require yaml extension for yaml - fix for plugin loader to always add original_path, even when not using all() - fix py3 issues - added --inventory as clearer option - return name when stringifying host objects - ajdust checks to code moving * reworked vars and vars precedence - vars plugins now load group/host_vars dirs - precedence for host vars is now configurable - vars_plugins been reworked - removed unused vars cache - removed _gathered_facts as we are not keeping info in host anymore - cleaned up tests - fixed ansible-pull to work with new inventory - removed version added notation to please rst check - inventory in config relative to config - ensures full paths on passed inventories * implicit localhost connection local
* removed bad ignore as host can override connectionBrian Coca2017-03-281-4/+0
| | | | also breaks testing network modules
* added docs to CLI docstringsaddedBrian Coca2017-03-241-1/+3
| | | | | removed 'now intermediate build files' from repo adjusted gitignore
* draft to generate man pagesBrian Coca2017-03-241-2/+4
|
* Retain vault password as bytes in 2.2 (#22378)Adrian Likins2017-03-071-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Retain vault password as bytes in 2.2 Prior to 2.2.1, the vault password was read in as byes and then remained bytes all the way through the code. A bug existed where bytes and text were mixed, leading to a traceback with non-ascii passwords. In devel, this was fixed by changing the read in password to text type to match with our overall strategy of converting at the borders. This was backported to stable-2.2 for the 2.2.1 release. On reflection, this should not have been backported as it causes passwords which were originally non-utf-8 to become utf-8. People will then have their working 2.2.x vault files become in-accessible. this commit pipes bytes all the way through the system for vault password. That way if a password is read in as a non-utf-8 character sequence, it will continue to work in 2.2.2+. This change is only for the 2.2 branch, not for 2.3 and beyond. Why not everywhere? The reason is that non-utf-8 passwords will cause problems when vault files are shared between systems or users. If the password is read from the prompt and one user/machine has a latin1 encoded locale while a second one has utf-8, the non-ascii password typed in won't match between machines. Deal with this by making sure that when we encrypt the data, we always use valid utf-8. Fixes #20398 (cherry picked from commit 5dcce0666a81917c68b76286685642fd72d84327)
* PEP 8 indent cleanup. (#20800)Matt Clay2017-01-291-9/+9
| | | | | | | | * PEP 8 E121 cleanup. * PEP 8 E126 cleanup. * PEP 8 E122 cleanup.
* spelling of Extraneous (#20116)Andrew Spiers2017-01-111-1/+1
|
* Fix 'vault rekey' with vault secret env varAdrian Likins2016-11-011-1/+1
| | | | | | | | | | | | | | | | | if ANSIBLE_VAULT_PASSWORD_FILE is set, 'ansible-vault rekey myvault.yml' will fail to prompt for the new vault password file, and will use None. Fix is to split out 'ask_vault_passwords' into 'ask_vault_passwords' and 'ask_new_vault_passwords' to make the logic simpler. And then make sure new_vault_pass is always set for 'rekey', and if not, then call ask_new_vault_passwords() to set it. ask_vault_passwords() would return values for vault_pass and new vault_pass, and vault cli previously would not prompt for new_vault_pass if there was a vault_pass set via a vault password file. Fixes #18247
* Refactor parsing of CLI args so that we can modify them in the base classToshio Kuratomi2016-10-061-3/+1
| | | | | | | | | | | | | | | | Implement tag and skip_tag handling in the CLI() class. Change tag and skip_tag command line options to be accepted multiple times on the CLI and add them together rather than overwrite. * Make it configurable whether to merge or overwrite multiple --tags arguments * Make the base CLI class an abstractbaseclass so we can implement functionality in parse() but still make subclasses implement it. * Deprecate the overwrite feature of --tags with a message that the default will change in 2.4 and go away in 2.5. * Add documentation for merge_multiple_cli_flags * Fix galaxy search so its tags argument does not conflict with generic tags * Unit tests and more integration tests for tags
* better handling of host lists (#17781)Brian Coca2016-09-281-3/+6
| | | | | | | | | | * better handling of host lists fixes #17762 * corrected message * fixed extras space
* win_shell/win_command changes + tests (#17557)Matt Davis2016-09-151-1/+1
|
* Move uses of to_bytes, to_text, to_native to use the module_utils version ↵Toshio Kuratomi2016-09-061-3/+3
| | | | | | | | (#17423) We couldn't copy to_unicode, to_bytes, to_str into module_utils because of licensing. So once created it we had two sets of functions that did the same things but had different implementations. To remedy that, this change removes the ansible.utils.unicode versions of those functions.
* Dynamic role include (#17401)Brian Coca2016-09-051-0/+4
| | | | | | | | | | | | | | * dynamic role_include * more fixes for dynamic include roles * set play yfrom iterator when dynamic * changes from jimi-c * avoid modules that break ad hoc TODO: should really be a config
* minor optimizationBrian Coca2016-06-031-2/+1
|
* Show a better error message when there is too much arguments (#16119)Michael Scherer2016-06-031-1/+4
| | | | | | | | If someone run: ansible all -m file state=present The error message is "Missing target hosts" which is misleading, since the target hosts is here, the problem is the missing '-a'.
* fixed confusing reporting when no hosts are matchedBrian Coca2016-05-311-2/+2
| | | | it was hitting 'empty inventory' warning.
* fixes to vault/copyBrian Coca2016-04-141-0/+2
| | | | | | | rm _del_ as it might leak memory renamed to tmp file cleanup added exception handling when traversing file list, even if one fails try rest added cleanup to finally to ensure removal in most cases
* Adds 'ansible_check_mode' boolean magic variableStrahinja Kustudić2016-04-081-0/+3
| | | | | * Makes it possible to pass any options variable to VariableManager by changing `load_options_vars(options)` in `lib/ansible/utils/vars.py`
* Should be errors=strict since we don't want to end up matching hosts like '???'Toshio Kuratomi2016-03-241-1/+1
|
* Fix using non-ascii for inventory hostname patterns with the CLI.Toshio Kuratomi2016-03-241-1/+2
|
* Properly use check_raw when using parse_kv in cli/ codeJames Cammarata2016-03-211-1/+2
| | | | Fixes ansible-modules-core#3070
* Rework the way ad-hoc filters inventory to match how cli/playbook does itJames Cammarata2016-02-251-5/+9
|
* termination handlingBrian Coca2016-02-101-9/+0
| | | | | | | - moved to base cli class to handle centrally and duplicate less code - now avoids duplication and reiteration of signal handler by reassigning it - left note on how to do non-graceful in case we add in future as I won't remember everything i did here and don't want to 'relearn' it.
* Revert "centralized TERM signal handling"Brian Coca2016-02-101-0/+8
| | | | | This reverts commit 5a88478ccca44c1b0d531a35e91e88f834db9210. is WIP, not ready for use yet