Commit graph

441 commits

Author SHA1 Message Date
Will Thames
9cb0c08d75 Ensure alternatives are displayed in deprecation warnings
Use plural `alternatives` key to display deprecation alternatives.
2018-01-09 21:21:53 -05:00
Matt Clay
15a04a3da7 Fix Python 3.7 syntax error. 2018-01-09 17:34:26 -08:00
Adam Miller
ad337503e7 add missing > to ansible-doc help message (#34512)
Signed-off-by: Adam Miller <admiller@redhat.com>
2018-01-06 15:43:54 +00:00
Brian Coca
87c75b19dd
dont warn on not matching 'all' (#32806)
* dont warn on not matching 'all'

the implicit localhost warning shoudl be enough

* centralized no hosts handling

also extended info on implicit only
2017-12-15 15:43:51 -05:00
Brian Coca
be5d68f3ad
add support for other scms to pull (#33152)
* add support for other scms to pull

* show choices for scms module in help
2017-12-13 22:16:54 -05:00
Brian Coca
afa82be019 make become prompt method agnostic (#33789)
fixes #33747
2017-12-13 17:57:06 -05:00
Andreas Olsson
b78ab37a94 Only expose rekey options to ansible-vault command
`ansible-vault` is the only cli command which knows how to handle the
rekey options `--new-vault-id` and `--new-vault-password-file`. No
point in exposing those rekey options to any of the other ansible
commands.

On a practical level I think this matters most in ensuring that
`--help` doesn't produce any false/unhelpful output.
2017-12-07 11:48:20 -05:00
Andreas Olsson
7bd54a51e2 Add --vault-id support to ansible-pull
Without this additional code snippet `ansible-pull` will still accept
the `--vault-id` option. It just won't pass the option along when
invoking `ansible-pull`.
2017-12-06 13:40:20 -05:00
Brian Coca
ebd08d2a01 jsonify inventory (#32990)
* jsonify inventory
* smarter import, dont pass kwargs where not needed
* added datetime
* Eventual plan for json utilities to migrate to common/json_utils when we split
  basic.py no need to move jsonify to another file now as we'll do that later.
* json_dict_bytes_to_unicode and json_dict_unicode_to_bytes will also
  change names and move to common/text.py at that time (not to json).
  Their purpose is to recursively change the elements of a container
  (dict, list, set, tuple) into text or bytes, not to json encode or
  decode (they could be a generic precursor to that but are not limited
  to that.)
* Reimplement the private _SetEncoder which changes sets and datetimes
  into objects that are json serializable into a private function
  instead.  Functions are more flexible, less overhead, and simpler than
  an object.
* Remove code that handled simplejson-1.5.x and earlier.  Raise an error
  if that's the case instead.
  * We require python-2.6 or better which has the json module builtin to
    the stdlib.  So this is only an issue if the stdlib json has been
    overridden by a third party module and the simplejson on the system
    is 1.5.x or less.  (1.5 was released on 2007-01-18)
2017-11-21 13:41:27 -08:00
Valentin Krasontovitsch
bf7f56f413 Fix typo in usage of encrypt_string command (#32961) 2017-11-19 14:20:57 +00:00
Brian Coca
23b1dbacaf
Config continued (#31024)
* included inventory and callback in new config

allow inventory to be configurable
updated connection options settings
also updated winrm to work with new configs
removed now obsolete set_host_overrides
added notes for future bcoca, current one is just punting, it's future's problem
updated docs per feedback
added remove group/host methods to inv data
moved fact cache from data to constructed
cleaner/better options
fix when vars are added
extended ignore list to config dicts
updated paramiko connection docs
removed options from base that paramiko already handles
left the look option as it is used by other plugin types
resolve delegation
updated cache doc options
fixed test_script
better fragment merge for options
fixed proxy command
restore ini for proxy
normalized options
moved pipelining to class
updates for host_key_checking
restructured mixins

* fix typo
2017-11-16 13:49:57 -05:00
Adrian Likins
86dc3c09ac
Fix vault --ask-vault-pass with no tty (#31493)
* Fix vault --ask-vault-pass with no tty

2.4.0 added a check for isatty() that would skip setting up interactive
vault password prompts if not running on a tty.

But... getpass.getpass() will fallback to reading from stdin if
it gets that far without a tty. Since 2.4.0 skipped the interactive
prompts / getpass.getpass() in that case, it would never get a chance
to fall back to stdin.

So if 'echo $VAULT_PASSWORD| ansible-playbook --ask-vault-pass site.yml'
was ran without a tty (ie, from a jenkins job or via the vagrant
ansible provisioner) the 2.4 behavior was different than 2.3. 2.4
would never read the password from stdin, resulting in a vault password
error like:

        ERROR! Attempting to decrypt but no vault secrets found

Fix is just to always call the interactive password prompts based
on getpass.getpass() on --ask-vault-pass or --vault-id @prompt and
let getpass sort it out.

* up test_prompt_no_tty to expect prompt with no tty

We do call the PromptSecret class if there is no tty, but
we are back to expecting it to read from stdin in that case.

* Fix logic for when to auto-prompt vault pass

If --ask-vault-pass is used, then pretty much always
prompt.

If it is not used, then prompt if there are no other
vault ids provided and 'auto_prompt==True'.

Fixes vagrant bug https://github.com/hashicorp/vagrant/issues/9033

Fixes #30993
2017-11-15 14:01:32 -05:00
Sloane Hertel
53ade280a3 clarify docs for --flush-cache (#32799) 2017-11-15 10:40:35 -05:00
Matt Davis
5ff36c3423 Enable autoloading of inventory plugins (#32709)
* Automatically loads and executes an inventory plugin specified by a standard YAML inventory config file containing a `plugin` key at its root.
* Moved inventory PluginLoader to a shared global instance.
2017-11-09 19:38:34 -05:00
Dag Wieers
9a6615a905
Make newer stuff PEP8 compliant (#26951)
So we fixed everything that was not a module to be PEP8 compliant, and
in the meantime these 5 new files were additionally disabled from PEP8
testing.

This fixes it.

Also update Copyright/License statements.
2017-11-05 11:27:41 +01:00
jctanner
c76ce54aee
Add -f/--list_files option to the ansible-doc command for faster list (#32524)
Add -f/--list_files option to the ansible-doc command for faster listing of plugins and show where they were found.
2017-11-02 21:29:55 -04:00
Jacob Floyd
ca8668f08b Use playbook callbacks for adhoc commands too
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.
2017-11-01 16:46:22 -04:00
Brian Coca
95b31a3b61
Playbook dir option (#32275)
* initial add of basedir

Allows you to set a 'playbook dir' for adhoc, inventory and console to allow for 'relative path loading'
2017-10-31 15:41:30 -04:00
Brian Coca
75a6f9dbc2
remove misleading group vars as they are flat (#32276)
* remove misleading group vars as they are flat

* fixed vars display
2017-10-30 12:59:43 -04:00
Toshio Kuratomi
2e12a5f8c2 Revert "Removed a force conditional (#28851)" (#32282)
This reverts commit 07acc579db.

On closer examination of this code, the conditional that had force in it
was not a parent of this one.  So handling of force is needed i both
branches.

See the recent comments on #23391
2017-10-28 18:35:32 +10:00
Brian Coca
ca71a50459 Avoid default inventory proccessing for pull (#32135)
* Avoid default inventory proccessing for pull

- now pull's own special inventory processing should work correctly
- also removed ineffective set_defaults

fixes #31449

* use class property instead

* only do localhost for adhoc

(cherry picked from commit aad5d1432583c4aa4105b774f38c80498e85de59)
2017-10-25 19:55:48 -04:00
Brian Coca
90e8071d48 fix inventory loading for ansible-doc
fixes #31995
2017-10-20 16:46:56 -04:00
Jerry Chong
4acd0de8f0 Remove extraneous comment block (#31865) 2017-10-18 11:08:29 +01:00
Ilya Margolin
9bc60cd05e Fix -M/--module-path option for ansible-doc and ansible-console (#31744)
Fixes #31743
2017-10-16 10:47:40 -04:00
Adrian Likins
297dfb1d50 Vault secrets script client inc new 'keyring' client (#27669)
This adds a new type of vault-password script  (a 'client') that takes advantage of and enhances the 
multiple vault password support.

If a vault password script basename ends with the name '-client', consider it a vault password script client. 

A vault password script 'client' just means that the script will take a '--vault-id' command line arg.

The previous vault password script (as invoked by --vault-password-file pointing to an executable) takes
no args and returns the password on stdout. But it doesnt know anything about --vault-id or multiple vault
passwords.

The new 'protocol' of the vault password script takes a cli arg ('--vault-id') so that it can lookup that specific
vault-id and return it's password.

Since existing vault password scripts don't know the new 'protocol', a way to distinguish password scripts
that do understand the protocol was needed.  The convention now is to consider password scripts that are
named like 'something-client.py' (and executable) to be vault password client scripts.

The new client scripts get invoked with the '--vault-id' they were requested for. An example:

     ansible-playbook --vault-id my_vault_id@contrib/vault/vault-keyring-client.py some_playbook.yml

That will cause the 'contrib/vault/vault-keyring-client.py' script to be invoked as:

     contrib/vault/vault-keyring-client.py --vault-id my_vault_id

The previous vault-keyring.py password script was extended to become vault-keyring-client.py. It uses
the python 'keyring' module to request secrets from various backends. The plain 'vault-keyring.py' script
would determine which key id and keyring name to use based on values that had to be set in ansible.cfg.
So it was also limited to one keyring name.

The new vault-keyring-client.py will request the secret for the vault id provided via the '--vault-id' option.
The script can be used without config and can be used for multiple keyring ids (and keyrings).

On success, a vault password client script will print the password to stdout and exit with a return code of 0.
If the 'client' script can't find a secret for the --vault-id, the script will exit with return code of 2 and print an error to stderr.
2017-10-13 15:23:08 -04:00
Brian Coca
83dec70ad8 validate that existing dest is valid directory 2017-10-12 14:19:58 -04:00
Brian Coca
74107ff7cc better message for unsupported include/imports
adhoc cannot currently execute these actions
2017-10-09 20:49:11 -07:00
Brian Coca
f00d47fac0 dont follow symlinks for inventories
now symlink dir is checked for locality of group/host_vars

fixes #31195
2017-10-04 11:04:32 -04:00
Adrian Likins
278ff19bea Handle vault decrypt --output=- (#31066)
In cli.CLI.unfrack_path callback, special case if the
value of '--output' is '-', and avoid expanding
it to a full path.

vault cli already has special cases for '-', so it
just needs to get the original value to work.

Fixes #30550
2017-10-03 12:02:16 -04:00
Brian Coca
fc745920c7 fixed pull's ansible/git invocation options (#30938)
* fixed ansible/git invocation options

now falls back to using localhost as 'all' does not include implicit accidentally anymore

fixes #30636

* better fix

* qfq9
2017-09-27 19:50:36 -04:00
Brian Coca
4291edd820 remove 'new internal vars' from dumps
fixes #30924
2017-09-27 16:10:42 -04:00
Brian Coca
7a312b6cf7 add ability to set default tags in config 2017-09-22 19:21:13 -04:00
Adrian Likins
174cb1f33c Check number of vault secrets after setup. (#30520)
This is to catch vault secrets from config and
cli. Previously vault_password_file in config was
missed since it was added by setup_vault_secrets,
so check after setup_vault_secrets.
2017-09-20 10:31:36 -04:00
Adrian Likins
307be59092 Don't ask for password confirm on 'ansible-vault edit' (#30514)
* Don't ask for password confirm on 'ansible-vault edit'

This is to match the 2.3 behavior on:

        ansible-vault edit encrypted_file.yml

Previously, the above command would consider that a 'new password'
scenario and prompt accordingly, ie:

        $ ansible-vault edit encrypted_file.yml
        New Password:
        Confirm New Password:

The bug was cause by 'create_new_password' being used for
'edit' action. This also causes the previous implicit 'auto prompt'
to get triggered and prompt the user.

Fix is to make auto prompt explicit in the calling code to handle
the 'edit' case where we want to auto prompt but we do not want
to request a password confirm.

Fixes #30491
2017-09-19 17:39:51 -04:00
Brian Coca
24d4787b2d Lookup docs (#30280)
* finalize lookup documentation
* minor fixes to ansible-doc
 - actually show which file caused error on when listing plugins
 - removed redundant display of type and name
* smart quote fixes from toshio
2017-09-19 10:49:07 -04:00
Brian Coca
8799038a89 deprecated include
added docs for new actions that take over include duties
2017-09-15 13:20:32 -07:00
Brian Coca
c027ad943e remove dupe deprecation on config (#30364)
* remove dupe deprecation on config

also move failed typing to same place to use 'standard' display vs hack.
2017-09-14 16:56:52 -04:00
Matt Clay
442af3744e Miscellaneous pylint fixes.
The following rules are no longer disabled:

- bad-format-string
- duplicate-key
- lost-exception
- trailing-newlines
- unexpected-keyword-arg
- useless-suppression
- using-constant-test
2017-09-13 01:53:08 -07:00
Brian Coca
2165bac212 module and vault fixes (#29663)
* module and vault fixes

- fix module_path cli option and usage, which fixes #29653
- move --output to be in subset of vault cli, no need for all vault enabled cli to use it
- added debug to loader to see directories added
2017-09-11 21:02:16 -04:00
Toshio Kuratomi
cfaea8a053 Change ansible-doc usage to show -a is for internal use (#29603)
* Change ansible-doc usage to show -a is for internal use

ansible-doc -a is for testing that documentation is sane.  It should not
be used by normal users in production.  The main reason for this is that
it is designed to fail if there are any undocumented modules or plugins.
This is good for testing that all plugins we ship are documented.  It is
not good for end users who may have undocumented third-party plugins.
2017-09-11 11:25:34 -07:00
Brian Coca
075ead8fb0 fixes to config/setting retrieval
- better variable precedence management
- universal plugin option handling
- also updated comments for future directions
- leverage fragments for plugins
- removed fact namespacing
- added 'firendly name' field
- updated missing descriptions
- removed some unused yaml entries, updated others to reflect possible future
- documented more plugins
- allow reading docs using alias
- short licenses
- corrected args for 'all plugins'
- fixed -a option for ansible-doc
- updated vars plugins to allow docs
- fixed 'gathering'
- only set options IF connection
- added path list and renamed pathspec mostly the diff is , vs : as separator
- readded removed config entries that were deprecated but had no message ... and deprecated again
- now deprecated entries give warning when set
2017-09-09 09:48:22 -07:00
Adrian Likins
89c973445c generate rst doc pages for command line tools (#27530)
* let generate_man also gen rst pages for cli tools
* make template-file, output-dir, output format cli options for generate_man
* update main Makefile to use generate_man.py for docs (man pages and rst)
* update vault docs that use :option:
* Edits based on
6e34ea6242 and
a3afc78535

* add a optparse 'desc' to lib/ansible/cli/config.py 

  The man page needs a short desc for the 'NAME' field
  which it gets from the option parse 'desc' value.

  Fixes building ansible-config man page.

* add trim_docstring from pep257 to generate_man

  use pep258 docstring trim function to fix up any indention
  weirdness inherit to doc strings (ie, lines other than
  first line being indented.

* Add refs to cli command actions

To reference ansible-vaults --vault-id option, use:

:option:`The link text here <ansible-vault --vault-id>`

or:

:option:`--vault-id <ansible-vault --vault-id>`

To reference ansible-vault's 'encrypt' action, use:

:ref:`The link text here <ansible_vault_encrypt>`

or most of the time:

:ref:`ansible-vault encrypt <ansible_vault_encrypt>`
2017-09-07 15:44:20 -04:00
Rene Moser
da488a8db5 config: use path list for default inventory
This allows to use a pathlist in the ansible.cfg:

  [default]
  inventory = path/inventory:other_path/inventory

Since ansible allows to use --inventory on CLI more then once, we should also support a pathlist in the config.
2017-09-07 00:09:07 -04:00
Brian Coca
c51a4bc57d ansible-config view fixes 2017-09-01 13:08:47 -04:00
Sam Doran
31dc5342f3 Do not try to process an empty metai/main.yml file
If an empty meta/main.yml file exists, ansible-galaxy threw an unhelpful exception. Now, a warning message is printed and the installation does not fail.

See https://stackoverflow.com/questions/45432994/ansible-galaxy-fails-on-dependency-with-empty-meta-main-yml
2017-08-31 13:50:01 -04:00
Brock R
07acc579db Removed a force conditional (#28851)
This `if not force:` conditional will never be false.  So there is no need for it.
2017-08-31 04:48:42 -04:00
Brian Coca
9f12d66506 fix ansible-config view 2017-08-30 10:27:28 -04:00
Brian Coca
e79b6a03fc fix plugin docs broken by previous commit (#28601)
* fix plugin docs broken by previous commit

also removed verbosity requirements, goes back to displaying all data by default

* pepe should be full by now
2017-08-29 12:41:46 -04:00
Adrian Likins
1f962bd937 Fix config value type for VAULT_IDENTITY_LIST (#28678)
Was using the 'value_type' key, but didn't get updated
to the new 'type' key in merge.

Fix playbooks cli so it uses VAULT_IDENTITY_LIST as well.
2017-08-28 10:13:14 -04:00
Toshio Kuratomi
af2073d057 metadata 1.1
* Add network value to support_by field.
* New support_by value, certified
* Deprecate curated in favor of certified
* Add conversion from 1.0 to 1.1 to metadata-tool
* Add supported by Red Hat field to ansible-doc output
2017-08-15 23:12:08 -07:00
Brian Coca
c27248db60 ansible-inventory cli tool (#22477)
* ansible-inventory cli tool

added vars dump to graph
made yaml inventory dump actual yaml inventory format
cleaner dump
fixed graph, no dump needed
add pulling in host/group vars
pep indentation crime
added docstring for manpage autodoc
remove ansible_facts from output
added api compat layer
allow import from new and old APIs
better conditional for <2.4
pe4+p4

test stuck on OS X (seems popular today) but passes rest, merging anyways
2017-08-15 16:45:54 -04:00
Brian Coca
f921369445 Ansible Config part2 (#27448)
* 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
2017-08-15 16:38:59 -04:00
Adrian Likins
8003437ebc prompt for new pass on create/encrypt if none specified (#28185)
* prompt for new pass on create/encrypt if none specified

Make 'ansible-vault' edit or encrypt prompt for a password
if none or provided elsewhere.

Note: ansible-playbook does not prompt if not vault password
is provided

* dont show vault password prompts if not a tty
2017-08-15 13:09:24 -04:00
Adrian Likins
5739bb075f Vault secrets default vault ids list (#28190)
* Add config option for a default list of vault-ids

This is the vault-id equilivent of ANSIBLE_DEFAULT_PASSWORD_FILE
except ANSIBLE_DEFAULT_VAULT_IDENTITY_LIST is a list.
2017-08-15 11:56:17 -04:00
Adrian Likins
e287af1ac8 Vault secrets empty password (#28186)
* Better handling of empty/invalid passwords

empty password files are global error and cause an
exit. A warning is also emitted with more detail.

ie, if any of the password/secret sources provide
a bogus password (ie, empty) or fail (exception,
 ctrl-d, EOFError), we stop at the first error and exit. 

This makes behavior when entering empty password at
prompt match 2.3 (ie, an error)
2017-08-15 11:01:46 -04:00
René Moser
13dec9259f galaxy-cli: selective install roles in requirements file (#21412)
* galaxy-cli: force install selected roles in requirements file

* only when requirements file but also handle uninstalled roles
2017-08-14 17:17:22 -04:00
giovannisciortino
d3e48a51f5 Add check mode support to ansible-pull (#28021)
Fixes #27989
2017-08-14 11:20:05 -04:00
Adrian Likins
82f550e8cd Add prompt formats for 2.3 compat ask-vault-pass (#27974)
The prompt_formats dict didn't get the 'prompt_ask_vault_pass'
item added for interactive --ask-vault-pass, which
caused "KeyError: u'prompt_ask_vault_pass'"

Fixes #27885
2017-08-10 09:34:16 -04:00
Adrian Likins
c38ff3b8f8 pylint fixes for vault related code (#27721)
* rm unneeded parens following assert
* rm unused parse_vaulttext_envelope from yaml.constructor
* No longer need index/enumerate over vault_ids
* rm unnecessary else
* rm unused VaultCli.secrets
* rm unused vault_id arg on VaultAES.decrypt()

pylint: Unused argument 'vault_id'
pylint: Unused parse_vaulttext_envelope imported from ansible.parsing.vault
pylint: Unused variable 'index'
pylint: Unnecessary parens after 'assert' keyword
pylint: Unnecessary "else" after "return" (no-else-return)
pylint: Attribute 'editor' defined outside __init__

* use 'dummy' for unused variables instead of _

Based on pylint unused variable warnings.

Existing code use '_' for this, but that is old
and busted. The hot new thing is 'dummy'. It
is so fetch.

Except for where we get warnings for reusing
the 'dummy' var name inside of a list comprehension.

* Add super().__init__ call to PromptVaultSecret.__init__
pylint: __init__ method from base class 'VaultSecret' is not called (super-init-not-called)

* Make FileVaultSecret.read_file reg method again

The base class read_file() doesnt need self but
the sub classes do.

Rm now unneeded loader arg to read_file()

* Fix err msg string literal that had no effect
pylint: String statement has no effect

The indent on the continuation of the msg_format was wrong
so the second half was dropped.

There was also no need to join() filename (copy/paste from
original with a command list I assume...)

* Use local cipher_name in VaultEditor.edit_file not instance
pylint: Unused variable 'cipher_name'
pylint: Unused variable 'b_ciphertext'

Use the local cipher_name returned from parse_vaulttext_envelope()
instead of the instance self.cipher_name var.

Since there is only one valid cipher_name either way, it was
equilivent, but it will not be with more valid cipher_names

* Rm unused b_salt arg on VaultAES256._encrypt*
pylint: Unused argument 'b_salt'

Previously the methods computed the keys and iv themselves
so needed to be passed in the salt, but now the key/iv
are built before and passed in so b_salt arg is not used
anymore.

* rm redundant import of call from subprocess
pylint: Imports from package subprocess are not grouped

use via subprocess module now instead of direct
import.

* self._bytes is set in super init now, rm dup

* Make FileVaultSecret.read_file() -> _read_file()

_read_file() is details of the implementation of
load(), so now 'private'.
2017-08-08 16:10:03 -04:00
10sr
000f8dcc8f Fix bug that diff.always = yes in ansible.cfg won't be respected (#27746) 2017-08-04 10:42:38 -04:00
Toshio Kuratomi
3f12fccd02 Fix several things causing tracebacks with unicode cwd (#27731)
Fixes #27511
2017-08-04 09:25:08 -04:00
Sam Doran
af558698a0 Include aliases in ansible-doc output (#27702)
* Properly include aliases in ansible-doc output

Use correct variable name for storing aliases and only print them out if the list isn't empty.

Fixes #24498

* Only include choices in output if choices exist in the list
2017-08-03 10:38:08 -07:00
Adrian Likins
75a8be9a5d Add back support for vault_password_file config var (#27597)
Got removed in arg parsing updates. Now added back in
setup_vault_secrets().

The default value for DEFAULT_VAULT_PASSWORD_FILE was also
set to '~' for some reason, change to to no default.

Add integration tests.
2017-08-01 18:07:33 -04:00
Adrian Likins
9f57920eab Fix --ask-vault-pass prompt to match old when poss (#27602)
If we don't use more than one vault-id, and we use
--ask-vault-pass, instead of using the new vault prompt
format ('Vault password (my_vault_id): ') we use the old
one ('Vault password: ').

This avoids confusing Tower when it needs to detect an
interactive vault password prompt.

This also potentially could allow vault password prompts
to be customized per vault_id.
2017-08-01 16:39:54 -04:00
Chris Houseknecht
e2651d4bac Give precedence to user supplied --roles-path option (#27524) 2017-07-31 18:46:49 -04:00
Adrian Likins
934b645191 Support multiple vault passwords (#22756)
Fixes #13243

** Add --vault-id to name/identify multiple vault passwords

Use --vault-id to indicate id and path/type

 --vault-id=prompt  # prompt for default vault id password
 --vault-id=myorg@prompt  # prompt for a vault_id named 'myorg'
 --vault-id=a_password_file  # load ./a_password_file for default id
 --vault-id=myorg@a_password_file # load file for 'myorg' vault id

vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.

Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.

Replace passing password around everywhere with
a VaultSecrets object.

If we specify a vault_id, mention that in password prompts

Specifying multiple -vault-password-files will
now try each until one works

** Rev vault format in a backwards compatible way

The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.

Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.

use 1.1 format for 'default' vault_id

Vaulted items that need to include a vault_id will be
written in 1.2 format.

If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2

vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.

** Changes/refactors needed to implement multiple vault passwords

raise exceptions on decrypt fail, check vault id early

split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()

some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback

fix py3 dict.keys() 'dict_keys object is not indexable' error

pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids

** Add a config option (vault_id_match) to force vault id matching.

With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).

In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.

If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.

Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 15:20:58 -04:00
Brian Coca
4fba9bf23b revert action loader changes to doc, due to error
restoring behaviour in which a missing module is a warning that shows paths searched,
patch incorrectly bypassed detection and ended up in an exception: global name 'module' is not defined
2017-07-25 16:33:30 -04:00
Michael Scherer
4811c7f117 Permit to have a action plugin without a empty module file
Currently, someone writing a action plugin will also need
to have a empty file in the module path to avoid triggering
the error "no action detected in task.".
2017-07-25 15:11:56 -05:00
Toshio Kuratomi
4e8b28e404 Switch from map and filter to list comprehensions and generator expressions (#27198)
One of the complex map + filter + lambda combinations here was causing
pylint to have a rare false positive detecting undefined variables.

Switch to list comprehensions and generator expressions which are
easi(er) to read for humans and do not confuse pylint.

References #27193
2017-07-22 19:12:35 -07:00
Toshio Kuratomi
ff22528b07 Consolidate boolean/mk_boolean conversion functions into a single location
Consolidate the module_utils, constants, and config functions that
convert values into booleans into a single function in module_utils.

Port code to use the module_utils.validate.convert_bool.boolean function
isntead of mk_boolean.
2017-07-17 11:48:05 -07:00
Toshio Kuratomi
3ee997b720 metadata and doc generator optimization and fixes
* Fix ansible-doc traceback when a plugin doesn't parse correctly
* Change extract_metadata ivocation to take either an ast or source
  code.  When given source code, it can find file offsets for the start
  and end of dict.  When given the ast, it is quicker as it doesn't have
  to reparse the source.  Requires changing the call to the function to
  use a keyword arg.
* Fix reading of metadata to find the last occurrence of
  ANSIBLE_METADATA instead of the first.
* Add some more unittests to get closer to complete coverage
2017-07-04 01:12:43 -07:00
Eugen C
6d59160744 Fix ansible ad-hoc to respect ANSIBLE_STDOUT_CALLBACK (#26098)
* Fix ansible ad-hoc to respect ANSIBLE_STDOUT_CALLBACK

* Ansible ad-hoc 'stdout_callback' should work only with 'bin_ansible_callbacks'
2017-06-26 16:01:06 -04:00
Abhijeet Kasurde
e8072ee616 Misc typo for Ansible
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2017-06-21 11:19:41 -04:00
Christopher Galtenberg
170fc42e80 Improve help text for extra-vars requiring @ for filename
(cherry picked from commit 1b34de89ee)
2017-06-21 07:08:35 -04:00
Matt Clay
3eea649cbb PEP 8 fixes. 2017-06-15 15:54:05 -07:00
Brian Coca
fedbf3666b fixed issue with paths separator and others
finished  normalizing of path handling
removed overloaded '-p' from init_paths option, it is for role_paths
removed expand_tilde and get_opt methods as both were redundant, adjusted rest of code
updated tests to match
2017-06-15 14:53:54 -04:00
Brian Coca
df2fcecd62 pager should not log
fixes #25719
2017-06-15 10:47:11 -04:00
Brian Coca
74842adc07 1st part of ansible config, adds ansible-config to view/manage configs (#12797)
* Start of ansible config project

moved configuration definitions to external yaml file vs hardcoded
 * updated constants to be a data strcutures that are looped over and also return origin of setting
changed to manager/data scheme for base classes
new cli ansible-config to view/manage ansible configuration settings
 * prints green for default/unchanged and yellow for those that have been overriden
 * added list action to show all configurable settings and their associated ini and env var names
 * allows specifying config file to see what result would look like
 * TBD update, edit and view options

removed test for functions that have been removed

env_Vars are now list of dicts
allows for version_added and deprecation in future
added a couple of descriptions for future doc autogeneration
ensure test does not fail if delete_me exists
normalized 'path expansion'
added yaml config to setup packaging
removed unused imports
better encoding handling

updated as per feedback

* pep8
2017-06-14 11:08:34 -04:00
jctanner
58db0da5a5 Fix pep8 extra lines error (#25666) 2017-06-13 13:59:23 -04:00
Brian Coca
37acb7423b add deprecation notice for sudo/su cli options (#23983)
* add deprecation notice for sudo/su cli options

* updated as per feedback
2017-06-13 10:46:09 -04:00
Abhijeet Kasurde
b89cb95609 Fix spelling mistakes (comments only) (#25564)
Original Author : klemens <ka7@github.com>

Taking over previous PR as per
https://github.com/ansible/ansible/pull/23644#issuecomment-307334525

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2017-06-12 07:55:19 +01:00
Rene Moser
fd3c92504a ansible-doc: fix exception for required field 2017-06-03 14:32:05 +02:00
Dag Wieers
5553b20828 Collated PEP8 fixes (#25293)
- Make PEP8 compliant
2017-06-02 12:14:11 +01:00
Abhijeet Kasurde
07be5f2b67 spelling fixes (non-trivial, changing messages) (#25094)
Multiple spell fixes in single commit.
Taking over existing PR as per comment -
https://github.com/ansible/ansible/pull/23645#issuecomment-304312275

Original Author: klemens <ka7@github.com>

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2017-06-01 10:45:19 +01:00
Brian Coca
16cc07a016 made doc more tolerant and recursive for spec 2017-05-31 19:38:20 -04:00
Brian Coca
b8448fdb90 path cli options now resolve relative paths to cli 2017-05-25 14:29:27 -04:00
Adrian Likins
ea3914f438 Show the ansible version if invoked with more than one -v (#22091)
* Show the ansible version if invoked with more than one -v

* use display.vv directly
2017-05-24 14:45:35 -04:00
Brian Coca
8f97aef1a3 Transition inventory into plugins (#23001)
* 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
2017-05-23 17:16:49 -04:00
John R Barker
ed2f13b3db Fix more module returns (#24782)
* Correct return structure

* typo
2017-05-18 17:38:10 +01:00
Toshio Kuratomi
e36d2f0bd0 ansible-doc snippet format changes
* ansible-doc -s is supposed to output a sample snippet of how you could
  add the module into a playbook.  These changes update the style:
  * Use yaml mappings instead of key=value
  * Use the module name directly instead of action: modulename
* Fixes a bug when displaying option descritpions which are yaml strings
  instead of lists.

This fixes in code the bad formatting reported in #24201
2017-05-04 09:08:19 -07:00
Brian Coca
31045d58c6 added versions to dep notices (#24019)
* added versions to dep notices

* pep7

* string
2017-04-27 12:48:31 -04:00
Sumedh Sidhaye
be6ca006a2 Corrected -su cmdline option to --su to be consistent with the man page entry (#23899)
Signed-off-by: Sumedh Sidhaye <ssidhaye@redhat.com>
2017-04-25 21:26:20 -07:00
Michael Scherer
78836ec0b9 Fix --force for unversionned requirements (#23391)
In current stable (2.2), ansible galaxy install --force do erase
a role, even if the version is not set. This commit should restore
that specific behavior, in accordance to people reports:
  https://github.com/ansible/ansible/issues/11266#issuecomment-273801480

It was also the behavior planned in the initial discussion:
"if you're not fixing versions in your roles file, then it's fine
to expect that the role will be reinstalled each time you run
ansible-galaxy install.", cf https://github.com/ansible/ansible/pull/12904
2017-04-21 07:40:47 -04:00
Adrian Likins
15bd7e48da Add ansible executable path (argv[0]) to --version (#22262)
For example:

    ansible 2.3.0 (argv0_in_version f53921093f) last updated 2017/03/03 13:33:31 (GMT -400)
      config file = /home/adrian/.ansible.cfg
      configured module search path = Default w/o overrides
      executable location = /home/adrian/src/ansible/bin/ansible

This should help troubleshooting install issues.
2017-04-03 14:01:59 -04:00
Adrian Likins
dbc0c01c86 Show 'ansible' python module paths in --version (#22264)
* Show 'ansible' python module paths in --version
2017-04-03 12:42:58 -04:00
Brian Coca
c0db6d79f6 minor correction to module path option docs 2017-03-28 11:43:58 -04:00
Brian Coca
99e298a2a6 removed bad ignore as host can override connection
also breaks testing network modules
2017-03-28 11:32:22 -04:00
scottb
ed413f2b28 Update vault.py
Edit for conciseness and clarity.
2017-03-24 15:52:36 -04:00
Brian Coca
2a2e02aea4 .--. . .--. ---.. / .. ... / .- -. -. --- -.-- .. -. --. 2017-03-24 15:52:36 -04:00
Brian Coca
18a7a1ec31 added docs to CLI docstringsadded
removed 'now intermediate build files' from repo
adjusted gitignore
2017-03-24 15:52:36 -04:00