Commit graph

192 commits

Author SHA1 Message Date
Brian Coca
9d37b0c8aa 01110000 01100101 01110000 00111000 00100000
01101100 01101001 01101110 01110100 01101001 01101110 01100111 00100000 01110011 01110101 01100011 01101011 01110011
2017-06-19 17:50:52 -04:00
Brian Coca
9d8721dbde properly track delegated host in loops
ansible_host can be pulled from inventory and not match inventory_hostname,
this can "loose" vars to a new host named by ansible_host vs the delegated host
fixes #25770
2017-06-19 17:50:52 -04:00
Adrian Likins
4befefd78c Try to show original exception info for yaml (and other) errors (#24468)
* show original exception for yaml (and other) errors

In places where we need to catch a yaml error and raise
an AnsibleError, add the orig yaml exc to the AnsibleError
via the orig_exc arg.

When the AnsibleError is displayed it will now include the
AnsibleError (AnsibleParserError for example) and the type
and message from the original yaml exception.

This provides more detail to the error messages related to
yaml errors.

This also improves errors from dataloader (for example,
previously if a wrong password was used for a vault encrypted
yaml file, the error was very vague and suggested yaml errors,
but now the message includes the original exception from vault
indicating the password was incorrect or missing).

Add a text note to playbook helper asserts. For playbook
syntax/layout errors that aren't yaml errors, but errors
indicating invalid data structures for a playbook/task/role/block,
we now include some info about where the assert was and
why it was raised.

In places we raise an AnsibleParserError in an except
clause, pass the original exception to AnsibleParserError via
orig_exc arg.

Make assorted error messages a little more specific (like
the playbook helper load methods)

* Revert "Include the original YAML error in syntax error messages"

This reverts commit 781bb44b02.
2017-06-09 13:13:15 -04:00
Brian Coca
a2cff554ee allow more 'backwards compatible' vars_plugins (#25451)
* allow more 'backwards compatible' vars_plugins

* better version relying on exceptions
2017-06-08 12:47:40 -04:00
Dag Wieers
5553b20828 Collated PEP8 fixes (#25293)
- Make PEP8 compliant
2017-06-02 12:14:11 +01: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
Dag Wieers
4f29662a9e ansible/vars/: PEP8 compliancy (#24685)
- Make PEP8 compliant
2017-05-16 18:51:27 +01:00
Toshio Kuratomi
1c05ed7951 Fix circular import with unsafe_proxy, template, and vars
template/__init__.py imported unsafe_proxy from vars which caused
vars/__init__.py to load.  vars/__init__.py needed template/__init__.py
which caused issues.  Loading unsafe_proxy from another location fixes
that.
2017-04-28 15:35:30 -07:00
Brian Coca
a108f0fcd3 avoid hosts 'pre templated warnings' (#23878)
* avoid hosts 'pre templated warnings'

fixed is_template failing on undefined
fixes #23057

* py3 compat
2017-04-24 15:19:52 -04:00
Brian Coca
79b9c585ea less code
(cherry picked from commit 20d9f79a5250e764ffeddb046aeb82b7824ed952)
2017-04-20 22:05:55 -04:00
Brian Coca
602a2bca1b fix vars file selection
fixes #17382
alternate to #22979

deal with cases in which group/host have . in name
updated as per feedbck
only be strict about extension when doing dirs
also avoid ~ endings
2017-04-20 11:44:26 -04:00
Brian Coca
00231c29ba Revert "keep ansible_local as top level var, always present"
This reverts commit 97cb2016d8.

It was causing issues downstream as facts seem to be merged back for
subsequent tasks. Will restore if I ever figure out how to avoid that.
2017-04-04 16:30:57 -04:00
Toshio Kuratomi
2fff690caa Update module_utils.six to latest (#22855)
* Update module_utils.six to latest

We've been held back on the version of six we could use on the module
side to 1.4.x because of python-2.4 compatibility.  Now that our minimum
is Python-2.6, we can update to the latest version of six in
module_utils and get rid of the second copy in lib/ansible/compat.
2017-03-23 13:35:05 -07:00
Brian Coca
97cb2016d8 keep ansible_local as top level var, always present 2017-03-23 01:25:39 -04:00
Matt Martz
3164e8b561 E501 fixes (#22879) 2017-03-22 20:50:28 -05:00
Brian Coca
4319ddd5de allow users to control group var merge order (#22580)
* allow users to control group var merge order

With ansible_group_priority var at each group will determine merge order with siblings,
falling back to sorted names when priority is equal as it did before.

Parent/children relationships still work as they did and have higher precedence than priority

* move priority setting to groups, sourc indep

* now both inventory and play group follow priority

* removed double exception handling
2017-03-16 14:02:43 -04:00
Brian Coca
dd8d699981 namespace facts (#18445)
* namespace facts

always namespace facts, make the polluting of 'main' conditional on config

* updated to 2.4

* Update intro_configuration.rst
2017-03-15 17:12:16 -07:00
Brian Coca
39ba55e5ac corrected host group ancestor management 2017-03-15 15:46:58 -04:00
James Cammarata
a2599cab79 Fix variable precedence of INI/script vars to be in-line with docs.
This commit also adds a new test script (ansible-var-precedence-check.py in code-smell/)
to provide us with another line of defense against precedence bugs going forward.

The precedence docs state that the INI vars have a lower precedence than group/host
vars files for inventory and playbooks, however that has not been the case since 2.0
was released. This change fixes that in one way, though not exactly as the docs say.
The rules are:

1) INI/script < inventory dir < playbook dir
2) "all" group vars < other group_vars < host_vars

So the new order will be (from the test script mentioned above):

8. pb_host_vars_file - var in playbook/host_vars/host
9. ini_host_vars_file - var in inventory/host_vars/host
10. ini_host - host var inside the ini
11. pb_group_vars_file_child - var in playbook/group_vars/child
12. ini_group_vars_file_child - var in inventory/group_vars/child
13. pb_group_vars_file_parent - var in playbook/group_vars/parent
14. ini_group_vars_file_parent - var in inventory/group_vars/parent
15. pb_group_vars_file_all - var in playbook/group_vars/all
16. ini_group_vars_file_all - var in inventory/group_vars/all
17. ini_child - child group var inside the ini
18. ini_parent - parent group var inside the ini
19. ini_all - all group var inside the ini

Fixes #21845
2017-03-02 17:07:00 -06:00
James Cammarata
eec88b63c2 Fix bug introduced in 0df3767 regarding undefined entries in HostVars
Fixes #21084
2017-02-15 16:22:31 -06:00
James Cammarata
0d418789a2 Revert "Fixing another corner case for security related to CVE-2016-9587"
This reverts commit bcceada5d9.
2017-02-10 08:27:26 -06:00
Matt Clay
2adc71fabc PEP 8 fix. 2017-01-31 13:38:05 -08:00
Brian Coca
f4b6b72c5b Warn reserved (#20567)
* removed unused vars

* added warning when using reserved vars

fixes #4816

* cleanup
2017-01-31 15:35:28 -05:00
Matt Clay
cb76200c7d PEP 8 E111 & E114 cleanup. (#20838) 2017-01-30 15:01:47 -08:00
Matt Clay
95789f3949 PEP 8 whitespace cleanup. (#20783)
* PEP 8 E271 whitespace cleanup.
* PEP 8 W293 whitespace cleanup.
* Fix whitespace issue from recent PR.
2017-01-27 15:45:23 -08:00
Computest
bcceada5d9 Fixing another corner case for security related to CVE-2016-9587 2017-01-11 15:52:58 -06:00
James Cammarata
a6fff93967 Fixing security bugs for CVE-2016-9587 2017-01-09 10:43:03 -06:00
Dag Wieers
41614fd8e6 Display proper error on group_vars syntax error
This fix ensures a proper error is shown when a group_vars files cannot
be parsed correctly. Without this patch you get:

```
[dag@moria ansible.testing]$ ansible-playbook test132.yml
ERROR! Unexpected Exception: dictionary update sequence element #0 has length 1; 2 is required
to see the full traceback, use -vvv
```

With this patch you get:
```
[dag@moria ansible.testing]$ ansible-playbook test132.yml
ERROR! Problem parsing file '/home/dag/home-made/ansible.testing/group_vars/test135': line 1, column 1
```

This fixes #18843
2016-12-16 21:13:41 -05:00
Brian Coca
f550b4541f bad/missing fact plugin is a warning (#19350) 2016-12-14 14:25:19 -05:00
Brian Coca
778c983ef9 ansible_playbook_python (#18530)
* ansible_playbook_python

fixes #18471

* fix tests

* removed dupe
2016-11-23 16:30:46 -05:00
James Cammarata
81aa12eb1b Rework how the Conditional class deals with undefined vars
Previously, the Conditional class did a simple check when an
AnsibleUndefinedVariable error was raised to see if certain strings were
present. This patch tries to be smarter by evaluating the variable contained
in the error string and compared to the defined/not defined conditionals in
the conditional string.

This also modifies the UndefinedError message from HostVars slightly to
match the format returned jinja2 in general, making it easier to match the
error message in the Conditional code.

Fixes #18514
2016-11-22 08:29:58 -06:00
James Cammarata
0df3767d4d When iterating over hostvars yield the hostname not the host object
Also fixes HostVars to raise the correct jinja2 error type.

Fixes #16836
2016-11-21 10:39:42 -06:00
James Cammarata
a83b00bbc0 Properly sort groups by name as well as depth when getting vars
Fixes #17243
2016-11-18 22:57:52 -06:00
James Cammarata
f7fe6dc19c Don't fail on missing vars files for delegated hosts
Fixes #17965
2016-11-17 11:59:09 -06:00
Brian Coca
5dd195b52f restore play_hosts variables to not show removed
Also adds ansible_play_hosts_all with original list of hosts the play targeted
2016-11-08 10:51:27 -05:00
stephane
a32e48555d Correct delegated_host_name check
In fb50698da3 a check for delegated_host_name being defined was added. Make this
check safer as it breaks some playbooks.
2016-10-11 11:15:53 -07:00
cinerama70
fb50698da3 Graceful error handling when delegate_to host null (#17453) (#17783)
Currently, if the host specified in delegate_to for a task is null,
Ansible will crash with a stack trace. Add a check for this state
and handle the error appropriately.
2016-09-28 19:24:32 -04:00
Brian Coca
86ea21a73d ansible_play_batch (#17779)
* ansible_play_batch

* added version added
2016-09-28 10:32:19 -04:00
Brian Coca
cf7822e201 remove bare vars and undefined from lookup lists (#17647)
https://docs.ansible.com/ansible/porting_guide_2.0.html#deprecated
2016-09-27 12:32:04 -04:00
j0hnsmith
4650d8910e Feature/add ansible play hosts all (#17498)
* refactor ignore_limits_and_restrictions

into ignore_limits and ignore_limitations

* add ansible_play_hosts_all

* update docs re ansible_play_hosts_all

* only use play.hosts when is has a value

* replace ansible_play_hosts with ansible_play_hosts_all

* remove unnecessary var
2016-09-23 11:17:46 -04:00
James Cammarata
23651b657e Create a raw lookup for hostvars that does not template the data
When using hostvars to get extra connection-specific vars for connection
plugins, use this raw lookup to avoid prematurely templating all of the
hostvar data (triggering unnecessary lookups).

Fixes #17024
2016-09-21 13:16:08 -05:00
nvigot
10f840e80d include_vars now properly deals with hash_behaviour (#15895) 2016-09-16 15:40:38 -04:00
Toshio Kuratomi
4ed88512e4 Move uses of to_bytes, to_text, to_native to use the module_utils version (#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.
2016-09-06 22:54:17 -07:00
Tobias Wolf
c23b11d212 [Inventory] Cache the result of enumerating groups and host names
for `VariableManager._get_magic_variables()`.

This saves a lot of time re-iterating the nearly always constant global
list of groups and their members.

Generate once and cache, and invalidate cache in case `add_host:` or
`group_by:` are used.
2016-09-01 06:19:49 -05:00
Brian Coca
bd9094c925 include_role (role revamp implementation) (#17232)
* attempt #11 to role_include

* fixes from jimi-c

* do not override load_data, move all to load

* removed debugging

* implemented tasks_from parameter, must break cache

* fixed issue with cache and tasks_from

* make resolution of from_tasks prioritize literal

* avoid role dependency dedupe when include_role

* fixed role deps and handlers are now loaded

* simplified code, enabled k=v parsing

used example from jimi-c

* load role defaults for task when include_role

* fixed issue with from_Tasks overriding all subdirs

* corrected priority order of main candidates

* made tasks_from a more generic interface to roles

* fix block inheritance and handler order

* allow vars: clause into included role

* pull vars already processed vs from raw data

* fix from jimi-c blocks i broke

* added back append for dynamic includes

* only allow for basename in from parameter

* fix for docs when no default

* fixed notes

* added include_role to changelog
2016-08-26 13:42:13 -04:00
James Cammarata
b617d62203 Don't use an unset playbook basedir when searching for hostgroup vars
The flag new_pb_basedir is not being utilized in Inventory._get_hostgroup_vars,
leading to the situation where an inventory with no playbook basedir set will
read host/group vars from the $CWD, regardless of the inventory and/or playbook
relative location. This patch corrects that by not using the playbook basedir
if it is unset (None).

This patch also corrects a bug in which the VariableManager would accumulate
host/group vars files, which could lead to incorrect vars files being used when
playbooks are run from different directories containing their own group/host vars
directories.

Fixes #16953
2016-08-17 16:28:48 -05:00
James Cammarata
06d4f4ad0e Move tasks/blocks to a single parent model 2016-08-08 15:58:46 -05:00
Brian Coca
f7570f1dc4 Implicit localhost ondemand (#16900)
* Revert "There can be only one localhost"

This reverts commit 5f1bbb4fcd.
this broke several usages of localhost, see #16882, #16898 and #16886

* ensure there is only 1 localhost

fixes #16886, #16882 and #16898

- make sure localhost exists before returning it
- optimzed host caching
- ensure we always return a host object
2016-08-02 10:39:00 -04:00
James Cammarata
d8a3feb976 Fix bug where getting role vars does not follow the dep chain
This bug was introduced in 3ced6d3, where getting vars from a role
did not follow the dep chain. This was originally hidden by the fact
that we got vars twice (from the block and from the roles directly).

Fixes #16729
2016-07-19 16:59:11 -04:00
James Cammarata
83e4a4048b Fix the way pull localhosts out of inventory for delegate_to
This patch corrects the way we look in the inventory hosts list for
implicit localhost entries when localhost aliases are used.

Fixes #16568
2016-07-04 11:25:53 -05:00