Commit Graph

83 Commits (46137127a238d8e4b86a648cfda972a90f22b729)

Author SHA1 Message Date
Brian Coca 46137127a2
ansible-config: ensure we get templated default (#82974)
AKA all defaults rendered
2 months ago
snipfoo 5f4e332e37
Fix condition for unquoting configuration strings from ini files (#82388)
* Add prefix to `origin` when configuration variables come from ini files

Fixes ansible#82387

This change was suggested by @bcoca in
https://github.com/ansible/ansible/pull/82388#discussion_r1424235728 and
https://github.com/ansible/ansible/pull/82388#discussion_r1424249732

When configuration variables come from an ini file, their `origin` is
now set to `ini: <file>`. Similarly, once supported, YAML configuration
files will have their `origin` as `yaml: <file>`.

Consequently, since unquoting configuration strings should happen if and
only if they come from an ini file, this condition boils down to testing
whether their `origin` starts with `ini:`.

* Do not add prefix to `origin` but explicitly pass `origin_ftype`

So as not to rely on a specific format of the `origin` string,
as suggested by @sivel in
https://github.com/ansible/ansible/pull/82388#issuecomment-1881714871
2 months ago
Matt Martz e0c91af45f
Remove os.environ compat for py2 and deprecate ansible.utils.py3compat (#82794) 3 months ago
Brian Coca bec27fb4c0
prettyfy ansible-doc (#75116)
* prettify ansibile-doc output

delimiters when no color
avoid triggering color mode for existing tests
all use _format to observe nocolor
more v more info
imporoved conditional display
updated version on -v
normalize role errors
expand role data, dedupe code, fix formatting on warning
fix bug with galaxy info
role list improvements:
 lists all roles (even w/o meta/argspec)
 specs now indented under role
 role only listed once
Updated tests to reflect format changes

Co-authored-by: Felix Fontein <felix@fontein.de>
4 months ago
Matt Clay 9f899f9492
Require `from __future__ import annotations` (#81902) 8 months ago
David-Ademola e91bf2248f
Update manager.py (#80926) 1 year ago
Matt Clay 2cd1744be3
Use ansible.module_utils.common.text.converters (#80704)
Replace use of old `ansible.module_utils._text` and add a unit test to maintain backwards compatibility.
1 year ago
Miklos Sagi b7ef2c1589
ansible-playbook -K breaks when passwords have quotes (#79837)
Now only 'unquote' when ini config file is the source
1 year ago
Matt Clay 833909ac19
Clean up unused imports in core (#79900)
* Clean up unused imports in core

* Add changelog fragment
1 year ago
Brian Coca 4115ddd135
plugin loader fix existing config testing (#78859)
create specific function to find config entry to avoid repopulating constantly
2 years ago
Brian Coca 9b79d6ba35
config error origin (#78407) 2 years ago
Brian Coca abdd237de7
Yolo (#77554)
* Revert "Revert "Config, ensure templating happens at functions (#77483)""

This reverts commit 94c9106153.

* removed update configdata, which is unused
* removed test for action we don't perform anymore
* removed unused configdata
2 years ago
Matt Clay 94c9106153 Revert "Config, ensure templating happens at functions (#77483)"
This reverts commit 6e5f1d781d.
2 years ago
Brian Coca 6e5f1d781d
Config, ensure templating happens at functions (#77483)
move away from special templating in constants.py
 simplified main get, unified paths to get info

* Let native jinja deal with eval for type
* make constants available for templating defaults
* ensure we use config file
2 years ago
Matt Clay f68c66a3ef Remove collections compat from controller code. 2 years ago
Matt Clay 0c4c18bc04 Type hint fixes. 2 years ago
Brian Coca 6d2d476113
avoid polluting vars with incorrect settings (#76590)
avoid polluting vars with incorrect settings

 simplify variables and templars
  - variables, original, only updated with final results, reset are copies of this
  - tempvars used for preliminary templating
  - cvars used for connection/shell/become plugins, delegation aware
  - vars_copy ignore tempvars updates and use connection plugin to get 
    finalized version per loop item/delegation,  also used to store temp results
    till we are ready to update 'variables'
 - fine tune nolog just cause we are here
 - also fix inventory_hostname_short for IP addresses
2 years ago
Brian Coca 04d4900518
config, moved 'choices info to keys (#76569)
* config, moved 'choices' from wall of text, to keys
* updated to ensure all pythons handle the 2 modes correctly
* Update lib/ansible/config/base.yml

Co-authored-by: Sandra McCann <samccann@redhat.com>
2 years ago
Brian Coca 864c2591b6
Use explicit keyword for plugin config (#75158)
* go back to keyword being explicit for plugin configs instead of using option name as implicit match
* switch spec to singular, no changes needed since no one used
2 years ago
Martin Krizek 0f95371131
Start of moving away from six (#75863)
ci_complete
3 years ago
Matt Martz 724800cd3f
Python 3.8 Controller Minimum (#74013) 3 years ago
Brian Coca d2d1f01f9d
avoid literal quoting in config lists (#74740)
* added tests
3 years ago
Matt Martz bf7d4ce260
Abstract away libyaml details into yaml utils (#72607)
* Add yaml utils file and use it

* Linting fix and missing import

* Abstract a few more details

* Parser imports

* Don't use CSafeDumper in AnsibleDumper

* Move and use convert_yaml_objects_to_native when libyaml is present

* yaml_load and yaml_dump, instead of safe_*

* re-use HAS_LIBYAML from utils.yaml

* add changelog fragment

* Address recent changes

* Use representer instead of recursive type converter

* Restore needed import

* move yaml utils to module_utils

* Properly guard imports

* Update from_yaml(_all)? to handle text wrappers with CSafeLoader

* Use yaml utils for legacy_collection_loader

* Add HAS_YAML, and ignore pylint issue

* oops

* GPL->BSD
3 years ago
Brian Coca b91749d671
fix config manager list loption with choices (#74267)
fixes #74225

  Co-authored-by: Kim Nørring <github@norring.dk>
3 years ago
Brian Coca 935528e22e
finish migrating ssh plugin to config system (#73708)
* finish migrating ssh plugin to config system

  fixes #72739
  fixes #57220

* fix connection detection in reset
* correct options for connection meta reset

Co-authored-by: David Shrewsbury <Shrews@users.noreply.github.com>
3 years ago
Matt Martz 950ab74758
Normalize ConfigParser between Python2 and Python3 (#73715)
* Normalize config parser between py2 and py3

* Add tests and changelog

* Use different config entry, since we supply certain env vars
3 years ago
Brian Coca 1202dd000f
Allow restricting config values to enumerated list (#73162)
* Allow restricting config values to enumerated list
* dont document internal entries
* also ignore private defs for ansible-config
* remove invalid value from tests
* added porting entry
3 years ago
Felix Fontein f569d80fde
Improve deprecations (#72697)
* Remove space before comma in '... bla , use ...'

* 'why' is inserted in the middle of a sentence, between two commas.

* Make deprecations from base.yml show source ansible-core.

* Add changelog fragment.

* Improve some more 'why's.

* Add PR URL to fragment.
4 years ago
Rick Elrod 3b40c6f3b7
[config] coerce more to string when 'type: str' (#72172)
Change:
- When a plugin defines `type: str` on a parameter, treat more kinds of
  input as a string instead of whatever it is parsed as.

Test Plan:
- New unit tests
- CI

Signed-off-by: Rick Elrod <rick@elrod.me>
4 years ago
Felix Fontein 8893a244b9
Validate plugin option type 'dict' / 'dictionary' (#71928)
* Validate option type 'dict' / 'dictionary'.

* Add changelog fragment.

* Change type of 'environment' to list.
4 years ago
Jordan Borean 3f22f79e73
Ensure -k is set to delegated hosts without a pass (#71136)
* Ensure -k is set to delegated hosts without a pass

* Fix up some broken tests

* Update task_executor.py

one possible fix, the other is updating winrm to normalize on 'password' like the other connection plugins

* Add alias for winrm and fix incorrect assumption

* Make sure aliases are used for keyword options

* Conditionally run test if sshpass is present, fix sanity

Co-authored-by: Brian Coca <bcoca@users.noreply.github.com>
4 years ago
Sloane Hertel 51f6d129cb
support hard coded module_defaults.yml groups for collections (#69919)
* Only allow groups which were hardcoded in module_defaults.yml

only load action groups from the collection if module_defaults contains a potential group for the action

* Fix tests using modules that override those whitelisted in lib/ansible/config/module_defaults.yml

Third party modules should not be using group/ - use the action name instead

* add externalized module_defaults tests

add the missing group and collections

ci_complete

Co-authored-by: Matt Davis <mrd@redhat.com>

* changelog

ci_complete

* Fix import in tests

ci_complete

* Update with requested changes

ci_complete

* don't traceback since we don't validate the contents of module_defaults

ci_complete

Co-authored-by: Matt Davis <mrd@redhat.com>
4 years ago
Martin Krizek 3606dcfe65
Ensure --version works with non-ascii project path (#66624)
Fixes #66617
4 years ago
Sloane Hertel 8eb00dd14c
Fix inline vaults for plugins in ensure_type (#67492)
* Fix implicit string - only looked right because of the vault __repr__
* Add tests for strings and implicit strings
4 years ago
Brian Coca 9ea5bb3364
strip spaces for each value in host list lists (#67701) 4 years ago
Jordan Borean 7092c196ed
config manager str type vault source (#65023)
* config manager str type vault source

* Convert vault text to_text earlier and add tests
5 years ago
Matt Davis b20a0f4831
text-ify config warning message (#63349) 5 years ago
Matt Davis 77de663879
config encode errors should not be fatal (#63311)
* fixes #63310
* subset of fixes from #58638
* added warning on error
5 years ago
Brian Coca a39b721db5
fixes to config manager (#58530)
* skip unreadable ansible.cfg

* all types should check for type

* patch access for tests and fix tests that relied on missing files not being checked
5 years ago
Sam Doran 6cf6f5a34b
Use atexit to cleanup tmp dirs (#56532)
* Wrap everything in try/except to avoid leaving files behind
* Add unit tests, integration tests, and changelog
* Do text the correct way
5 years ago
Sloane Hertel 47b2cb748b Allow config boolean options to default to None (#55951)
* Allow plugin boolean options to default to None

* fix mistake

* changelog

* be more specific
5 years ago
Sloane Hertel 54be769e8d fix AWS plugin credential precedence for environment variables (#52945)
* fix AWS plugin credential precedence for environment variables

* Allow aliases in direct plugins options

Consolidate precedence fix just in the doc fragment using aliases for mismatched options

* Access options with the option name rather than alias

* fix indentation

* update unit tests

* Improve readability
5 years ago
Abhijeet Kasurde ef8be6a599 Fix wrong number of arguments in string format (#53265)
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
5 years ago
Brian Coca 5e9b089ec2
Avoid resolving module_paths for docs (#51453)
alternate to #51419
5 years ago
Matt Martz 445ff39f94
Become plugins (#50991)
* [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
5 years ago
Matt Clay 48bdb61870 Fix path encoding bug in config manager. 5 years ago
Matt Clay 465df0ef8d
Fix encoding issues with file paths. (#50830)
* Fix encoding issues with file paths.

Discovered while testing with ANSIBLE_CONFIG env var set to a path
that contained unicode characters while LC_ALL=C.

* Fix unit tests.

* Fix another path encoding issue.
5 years ago
Abhijeet Kasurde 44bd8fc0a8 Update unit tests for configmanager
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
6 years ago
Abhijeet Kasurde 013c42b14f
Misc typo fixes (#49816)
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
6 years ago
Brian Coca 70ba960f6d
More specificity in errors for cfg mgr (#48995)
* More specificity in errors for cfg mgr
6 years ago