Commit Graph

56 Commits (083aef65ade1f7448ce98f8afaf70b797eead83d)

Author SHA1 Message Date
Toshio Kuratomi fa2edfa1ef * Make sure we don't sometimes get byte strings instead of unicode strings
* Turn strings into byte strings before passing to shlex and turn them
  back into unicode strings after they are retyurned from there

  Fixes #12257
2015-09-09 01:24:11 -07:00
Toshio Kuratomi e67459df86 Fix docstring of parse_value() to be informative 2015-09-09 01:24:11 -07:00
James Cammarata ff9f5d7dc8 Starting to add additional unit tests for VariableManager
Required some rewiring in inventory code to make sure we're using
the DataLoader class for some data file operations, which makes mocking
them much easier.

Also identified two corner cases not currently handled by the code, related
to inventory variable sources and which one "wins". Also noticed we weren't
properly merging variables from multiple group/host_var file locations
(inventory directory vs. playbook directory locations) so fixed as well.
2015-09-04 16:41:38 -04:00
Abhijit Menon-Sen 745ecd4845 Sanitize IPv6 hostname/port handling
Now we accept IPv6 addresses _with port numbers_ only in the standard
[xxx]:NN notation (though bare IPv6 addresses may be given, as before,
and non-IPv6 addresses may also be placed in square brackets), and any
other host identifiers (IPv4/hostname/host pattern) as before, with an
optional :NN suffix.
2015-08-20 22:06:44 +05:30
Abhijit Menon-Sen 74aab6f726 Use a self._raise_error helper and avoid passing the lineno around
Based on a patch by @Richard2ndQuadrant.
2015-08-20 22:05:17 +05:30
Abhijit Menon-Sen 9133cd409c Make _parse take an array of input lines as an argument
(There's no compelling reason to do this right now, but should be parser
need to be called multiple times in future, this makes it easier.)
2015-08-20 22:05:17 +05:30
Abhijit Menon-Sen 98a1905796 Rename 'section' to 'groupname' to better reflect its purpose 2015-08-20 22:05:17 +05:30
Abhijit Menon-Sen 1284c49bd7 Rewrite the INI InventoryParser
The new code parses INI-format inventory files in a single pass using a
well-documented state machine that reports precise errors and eliminates
the duplications and inconsistencies and outright errors in the earlier
three-phase parsing code (e.g. three ways to skip comments). It is also
much easier now to follow what decisions are being taken on the basis of
the parsed data. The comments point out various potential improvements,
particularly in the area of consistent IPv6 handling.

On the ornate marble tombstone of the old code, the following
inscription is one last baffling memento from a bygone age:

-    def _before_comment(self, msg):
-        ''' what's the part of a string before a comment? '''
-        msg = msg.replace("\#","**NOT_A_COMMENT**")
-        msg = msg.split("#")[0]
-        msg = msg.replace("**NOT_A_COMMENT**","#")
-        return msg
2015-08-20 22:05:17 +05:30
Brian Coca 5fec11f513 capture parsing exceptions and give nice error and location 2015-08-12 23:27:00 -04:00
Brian Coca f16b745f17 now properly uses default port if defined 2015-07-31 12:01:58 -04:00
James Cammarata 49a6601856 Further cleanup of internal use of ansible_ssh_host 2015-07-27 10:42:39 -04:00
James Cammarata ce3ef7f4c1 Making the switch to v2 2015-05-03 21:47:26 -05:00
Toshio Kuratomi 084fbbdea9 Reverse the conditional so there's one less return from this function 2015-02-26 22:50:11 -08:00
Alvaro Lopez Ortega 2e929cf0ce Fixes bug #10281 - Trailing zeros were truncated from strings 2015-02-21 19:54:38 +01:00
Alvaro Lopez Ortega a14248ffe1 Fixes bug #10281 - Trailing zeros were truncated from strings 2015-02-21 16:40:50 +01:00
Thomas Quinot 23d959db71 Report location (filename and line number) for inventory syntax errors
When AnsibleError is raised for a syntax error in an inventory file,
report filename and line number to help pinpointing the error.
2014-11-30 10:41:09 +01:00
Serge van Ginderachter 0ceefbbf29 inventory ini parser: do not add all the groups to *all* group
but only those with lowest depth, so we keep a proper tree structure
2014-03-25 12:45:00 +01:00
Oleg Bulatov f6a4c20cc0 Make parsing variables for hosts and groups more consistent
This commit allows to specify arrays in [group:vars] block.

Signed-off-by: Oleg Bulatov <oleg@bulatov.me>
2014-03-16 21:47:26 +04:00
Cristian Ciupitu 0749112286 Micro-optimization: replace s.find(x)!=-1 with x in s
timeit shows a speedup of ~3x on Python 2.7.5 x86_64.
It also makes the code a bit shorter.
2014-03-16 13:10:28 -04:00
Richard C Isaacson 16fe09eef8 Fixes related to uncommenting test_dir_inventory in TestInventory.
0. Uncomment the test.
1. Test fails.
2. Make vars unique per file in test inventory files.
3. Modify token addition to not ast.literal_eval(v) a variable containing a hash.
4. Modify vars to have an escape in test inventory file.
5. Catch exceptions explicitly. Any unknown exceptions should be a bug.
6. Test passes.
2014-03-06 12:09:53 -06:00
Michael DeHaan 94a7fb60fe Allow escaped comments in inventory files. 2014-03-05 20:10:25 -05:00
Richard C Isaacson b41d8106ff Revert "Merge pull request #6287 from risaacson/fix_hash_in_var"
This reverts commit a808287451, reversing
changes made to 6129ea7566.
2014-03-05 14:49:30 -06:00
Richard C Isaacson 38abd5e20e Break this out into a reusable function and document regex shortcomings. 2014-03-05 10:50:58 -06:00
Richard C Isaacson 49bd8b0b35 Fix inventory for test_dir_inventory
It came up that fixing this unit test may relate to another ticket that is open. This work allows us to uncomment this unit test by fixing how we pars variables allowing a quoted variable to contain a '#'.

Work also went into cleaning up some of the test data to clarify what was working.

Lastly work went into cleaning up formatting so that the code is easily read.
2014-03-04 18:31:49 -06:00
Ilya Kuznetsov 0658847ea6 Allow equal sign in single-line ini variables 2014-02-14 20:04:23 +07:00
jctanner 59d99c17b3 Merge pull request #5337 from bob-smith/bugfixFQDNParsing
Fix inventory parsing so that FQDN can be parsed without throwing ssh port error
2014-01-14 08:28:38 -08:00
Michael DeHaan 10350d1639 Update various copyrights. Not complete, but sufficient. 2014-01-04 13:32:04 -05:00
John Barker 4bf9f714d0 Fix inventory parsing so that FQDN can be parsed without throwing ssh
port parsing errors
Fixes problesm introduced by 948d019fef
Adds testcases to defend
2013-12-18 21:33:05 +00:00
Martynas Mickevicius 7ecb5fbc9c Handle comment on inventory group line. 2013-10-17 13:16:35 +03:00
Martynas Mickevicius 44279ce34f Allow leading ranges in the inventory host entries. 2013-10-17 13:16:35 +03:00
James Cammarata 948d019fef Detect IPv6 addresses in INI inventory
Prevents parts of the IPv6 address from being interpreted as a port
(for example, :80).

Fixes #3888
2013-10-09 11:11:09 -05:00
James Cammarata bff47df5ff Fix issue with ast evaluation of strings 2013-10-01 09:20:48 -05:00
Brian Coca 771435deb4 now ini vars are typed
Signed-off-by: Brian Coca <briancoca+dev@gmail.com>
2013-09-26 18:29:17 -04:00
Brian Coca a937a6a66d now bad ini entries will throw friendlier error
Signed-off-by: Brian Coca <briancoca+dev@gmail.com>
2013-08-07 12:49:12 -04:00
rishid d18c90ed8f Add support for INI comments that begin with '#' or ';'
Ini file format does not have a standard but ';' is used more often than '#' for comments
2013-08-06 11:41:07 -04:00
Rike-Benjamin Schuppner 71afb9e432 Use with guard for file reads. 2013-06-10 17:16:31 +02:00
Pol Llovet 4432c01ceb Handle '#' in var strings by splitting on ' #'
If someone has a " #" in a quoted var string, it
will interpret that as a comment and refuse to
load the inventory file due to an unbalanced
quote. Noisy failure > unexpected behavior.
2013-05-31 12:34:45 -06:00
Pol Llovet ba78360c52 Remove inline comments from inventory tokenizing. 2013-05-30 14:12:23 -06:00
Seth Vidal 2796b5ee2a simple fix for issue 2564
when we encounter a group we've not seen before - we need
to make sure we make it a subgroup of 'all', no matter what
2013-04-04 12:44:39 -04:00
Daniel Hokka Zakrisson 647cd0141c Move all inventory script code into the script parser 2013-03-01 23:22:52 +01:00
Nigel Metheringham c0e28762f0 Allow end of line comments in inventory file
See github issue 2702
https://github.com/ansible/ansible/issues/2072
2013-02-13 14:15:22 +00:00
Michael DeHaan 4bcdd24688 Merge pull request #1776 from junegunn/inventory-group-var-ws
Allows whitespaces around assignment operators when defining group variables
2012-12-17 16:51:49 -08:00
Junegunn Choi 8896486606 Adds comments on handling quoted group vars 2012-12-16 10:32:05 +09:00
Junegunn Choi 7fbb7e079a Fix hostname expansion bug in inventory parser 2012-12-16 01:49:12 +09:00
Junegunn Choi daf797804b Allows whitespaces around assignment operators
when defining group variables
2012-12-14 20:43:29 +09:00
Daniel Hokka Zakrisson 0c70abfaa9 Make sure any existing groups gets reused 2012-11-25 12:42:30 +01:00
Daniel Hokka Zakrisson 5504f13c68 Create groups in the first run through the file
Fixes #1208.
2012-11-25 01:00:14 +01:00
Michael DeHaan f140332ff6 Make it possible in the inventory file to have spaces in host variables 2012-08-30 19:51:46 -04: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