Commit Graph

48 Commits (f63b8878fd0d49f9f7d75f8433ff4919a6dc9b6a)

Author SHA1 Message Date
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
Brian Coca af88e34831 better error when host inventory script isnt dict 2016-01-25 16:32:09 -05:00
Tobias Wolf d6ae9e2c29 Avoid recursively checking JSON inventory for Unicode
by moving to en-bloc unicode conversion to act on scripts stdout

Both python-json and simplejson always return unicode strings when using
their loads() method on unicode strings. This is true at least since
2009. This makes checking each substring unnecessary, because we do not
need to recursively check the strings contained in the inventory dict
later one-by-one

This commit makes parsing of large dynamic inventory at least 2 seconds
faster.

cf: https://github.com/towolf/ansible-large-inventory-testcase
2016-01-21 17:35:40 +01:00
Emil Lind b0fe705384 Allow InventoryScript JSON with childgroups only
and without hosts and vars

Without this patch, the simplified syntax is triggered when a group
is defined like this:

    "platforms": {
        "children": [
            "cloudstack"
        ]
    }

Which results in a group 'platforms' with 1 host 'platforms'.

more details in https://github.com/ansible/ansible/issues/13655
2016-01-08 13:52:44 +01:00
Toshio Kuratomi d26d76ea58 Fix typo 2016-01-06 15:46:42 -08:00
Toshio Kuratomi 46903c80fa More fixes for unicode handling in the connection plugins.
Tested that ssh, docker, local, lxc-libvirt, chroot all work with the
updated unicode integration test.
2016-01-06 15:19:40 -08:00
Toshio Kuratomi a17ae6f07e Clean up pyflakes warnings in inventory 2015-10-19 11:13:56 -07:00
Toshio Kuratomi baa309309d Bundle a new version of python-six for compatibility along with some code to make it easy for distributions to override the bunndled copy if they have a new enough version. 2015-10-16 08:21:28 -07:00
Victor Salgado 54f1560d3e Fix mutable default argument 2015-09-16 16:49:45 -03:00
James Cammarata c8f2483d6d Cleaning up default group creation in inventory parsers 2015-09-16 12:54:54 -04:00
Marius Gedminas 823677b490 Replace .iteritems() with six.iteritems()
Replace .iteritems() with six.iteritems() everywhere except in
module_utils (because there's no 'six' on the remote host).  And except
in lib/ansible/galaxy/data/metadata_template.j2, because I'm not sure
six is available there.
2015-09-03 09:23:27 +03:00
Marius Gedminas 0c6ce31f76 Use 'except ... as' syntax
This syntax works on Python 2.6 through 3.x.  lib/ansible/module_utils
(and lib/ansible/modules) need to support Python 2.4, so I didn't touch
those.
2015-08-27 22:15:04 +03:00
Toshio Kuratomi 96836412aa Make error messages tell which inventory script the error came from 2015-06-03 11:51:33 -07:00
Toshio Kuratomi 1c8527044b Fix error handling when pasing output from dynamic inventory 2015-06-03 11:29:20 -07:00
James Cammarata ce3ef7f4c1 Making the switch to v2 2015-05-03 21:47:26 -05:00
Brian Coca c3d34a5386 Merge pull request #8936 from srvg/inventoryscript_onlychildren
Allow InventoryScript JSON with childgroups only
2015-03-05 17:11:04 -05:00
Toshio Kuratomi a63e4c595f Another place that needs to be json_dict_bytes_to_unicode 2015-01-26 22:04:51 -08:00
Toshio Kuratomi 0f6b87d33e Revert "Fix import statements" -- those impotrt statements were right
before... something else is fishy

This reverts commit 8ab536fbf2.
2015-01-26 22:01:52 -08:00
Toshio Kuratomi 8ab536fbf2 Fix import statements 2015-01-26 21:49:09 -08:00
Toshio Kuratomi 915d232d5f jinja2 cannot handle byte strs with non-ascii. So we need to transform potential byte str into unicode type. This fix is for dynamic inventory.
Fixes #10007
2015-01-26 20:39:09 -08:00
Brian Coca 6b3d0f4788 now captures returncode errors on inventory scripts 2015-01-15 13:38:25 -05:00
Toshio Kuratomi a10d10f647 Workaround more python-2.6 shlex not being able to handle unicode strings 2014-10-08 14:30:36 -04:00
Toshio Kuratomi cef2a8795f Make dynamic inventory return byte str, not unicode 2014-10-02 20:27:06 -04:00
Michael DeHaan 26cdddaebf Tracebacks are now catchable with ignore_errors and have streamlined output. Also removes 'baby-JSON' for bash modules. 2014-09-11 12:27:21 -04:00
Serge van Ginderachter 69740b86e8 Allow InventoryScript JSON with childgroups only
and without hosts and vars

Without this patch, the simplified syntax is triggered when a group
is defined like this:

    "platforms": {
        "children": [
            "cloudstack"
        ]
    }

Which results in a group 'platforms' with 1 host 'platforms'.

	modified:   lib/ansible/inventory/script.py
2014-09-09 11:37:54 +02:00
Serge van Ginderachter 3a228b9d55 InventoryScript: better syntax checking for json stream 2014-08-21 18:06:07 +02:00
James Cammarata bcf83cbc24 Merge branch 'sergevanginderachter-inventorytree' into svg_and_inventory_refactor 2014-07-07 13:11:52 -05:00
Michael DeHaan c2ac8fda1e Data from inventory scripts should be able to use nested Jinja2 expressions. 2014-07-03 16:11:14 -04:00
James Cammarata 8ed6350e65 When parsing json from untrusted sources, remove templating tags 2014-07-01 14:14:14 -05:00
Serge van Ginderachter be58808fe4 inventory script parser: do not add all the groups to *all* group 2014-03-25 12:45:00 +01:00
Michael DeHaan 10350d1639 Update various copyrights. Not complete, but sufficient. 2014-01-04 13:32:04 -05:00
Stoned Elipot 6cbd94dfae Avoid duplicates of the 'all' group when using inventory script.
Do not recreate an 'all' group when it is in the inventory script's
output, but use the one created upfront.
2013-09-02 12:26:02 +02:00
Matt Saunders 9fd1b174f5 Fixed tiny bug with _meta handling in external inventory scripts 2013-08-19 18:54:30 +01:00
Michael DeHaan 8955ac1eda If the result of a dynamic inventory script contains a "_meta" hash at top level
and the _meta hash contains a "hostvars", don't call --host hostname for any elements
and just serve them directly for performance enhancements with the external inventory
script and a large number of hosts.
2013-08-04 11:34:42 -04:00
Darryl Stoflet c0baf10845 Support for all:vars in script inventories 2013-06-02 14:54:29 -07:00
Timothy Appnel b15cc3e2b4 Fixed bug where a host entry in the inventory represented as a dict w/o a hosts or vars key was treated as a group and its vars essentially ignored. 2013-05-08 13:55:50 -04:00
Michael DeHaan d8bf87b008 (A) include errors in inventory scripts should they occur.
(B) allow registration with ignore_errors: True
2013-04-17 22:27:00 -04:00
Blair Zajac 36b3fc3acf Fix for inventory scripts with no path prefix that are in CWD.
Without this, using '-i ec2.py' will not work if '.' is not in PATH.
2013-04-05 20:52:59 -07:00
Daniel Hokka Zakrisson 647cd0141c Move all inventory script code into the script parser 2013-03-01 23:22:52 +01:00
Michael DeHaan a894791767 Slightly friendlier error on missing hosts file, slightly friendlier error on inventory script returning invalid syntax
(or if inventory is non-script and accidentally executable).
2013-02-09 11:37:55 -05:00
Daniel Hokka Zakrisson 8d309e0fa3 Allow inventory scripts to define groups of groups and group vars 2012-11-28 23:37:29 +01:00
Daniel Hokka Zakrisson 2bfb7deec0 Set all in the returned dict
Otherwise the group is lost, and group_vars/all isn't used.
2012-11-25 00:15:22 +01:00
Dag Wieers 89206a6b68 Fix for an exception when for whatever reason the inventory script fails
This avoids a traceback that gave no clue as to what was happening.
2012-11-06 16:39:10 +01:00
Jeroen Hoekx 23a62f5a78 Return multiple groups from inventory API. 2012-10-10 18:35:45 +02:00
Dave Peticolas 08272dc25d Remove unused imports. 2012-08-09 21:35:22 -07:00
Michael DeHaan faed4b5a33 whitespace + remove deprecated YAML parser (migration script lives in examples/scripts and warning was added
in 0.6 release)
2012-08-06 20:07:02 -04:00
Michael DeHaan 1754de3335 Misc code cleanup, mostly whitespace preferences, removing unused imports, plus a few fixes here and there. 2012-07-15 12:29:53 -04:00
Michael DeHaan cf9ddf3a30 Reorganizing file structure. Not done. 2012-05-25 19:34:13 -04:00