Commit Graph

432 Commits (cadfd56304e26405f05584b32f069b3726ea4242)

Author SHA1 Message Date
Brian Coca 61a30e5f49 better exception handling with delegated hosts 10 years ago
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.
10 years ago
James Cammarata d19fe8d95d Fetch vars for host directly when calculating the delegated user
This fixes the case in which the delegated to host may not be in the
specified hosts list, in which cases facts/vars for the host were
not available in the injected hostvars.

This also fixes the inventory variable fetching function, so that an
unknown host raises a proper error as opposed to a NoneType exception.

Fixes #8224
10 years ago
Toshio Kuratomi a10d10f647 Workaround more python-2.6 shlex not being able to handle unicode strings 10 years ago
Toshio Kuratomi cef2a8795f Make dynamic inventory return byte str, not unicode 10 years ago
Michael DeHaan 26cdddaebf Tracebacks are now catchable with ignore_errors and have streamlined output. Also removes 'baby-JSON' for bash modules. 10 years ago
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
10 years ago
Serge van Ginderachter 3a228b9d55 InventoryScript: better syntax checking for json stream 10 years ago
Serge van Ginderachter a1f09bd89f Merge variables for hosts instead of updating in get_variables() 10 years ago
Serge van Ginderachter 0ab721d51e better logic for all-group variables for implicit localhost 10 years ago
Serge van Ginderachter a2cfe8770b Inventory: fix logic mistake in loading/retrieving variables for groups 10 years ago
James Cammarata e3895840d1 Make sure group_vars/all is loaded for ungrouped hosts
Fixes #6563
10 years ago
James Cammarata b4476c238f Use match() instead of search() for pattern matching
Also related to f48fa3, fix for #8614
10 years ago
James Cammarata f48fa3759a Fix host pattern matching and enhance error detection
Fixes #8614
10 years ago
James Cammarata bea0845322 Fix vault_password positional args error 10 years ago
Michael DeHaan 8c4161d4a1 Merge branch 'retf_py' of git://github.com/berendt/ansible into devel
Conflicts:
	lib/ansible/inventory/vars_plugins/group_vars.py
	plugins/callbacks/mail.py
10 years ago
Serge van Ginderachter 7c96f1d803 InventoryDir: fixing yet another corner case 10 years ago
Serge van Ginderachter e8b45a9ef7 Invalidate host/group variables cache when loading
extra varsiables based on playbook basedir.
10 years ago
Serge van Ginderachter d39ff55688 Fix logic bug when loading vars for a new playbook basedir. 10 years ago
James Cammarata 4e5eb7559e Merge branch 'svg_and_inventory_refactor' into devel 11 years ago
Dan Slimmon 307a3e8a9c Fixed regex square-bracket bug.
Regexes were being parsed like ordinary ansible host patterns, so
square-bracket groups were getting interpolated wrongly.
11 years ago
James Cammarata aa261bdd14 Optimizing groups_for_host() lookup in inventory 11 years ago
James Cammarata fe892fccb1 Merge remote-tracking branch 'svg/varsplugins_refactor' into svg_and_inventory_refactor 11 years ago
James Cammarata 11a5fc85f4 Merge branch 'inventory_refactoring' into svg_and_inventory_refactor 11 years ago
James Cammarata bcf83cbc24 Merge branch 'sergevanginderachter-inventorytree' into svg_and_inventory_refactor 11 years ago
Serge van Ginderachter ff4119adc0 Performance optimization in resolving host patterns
Avoid resolving a pattern that is a plain host. When matching a hostname in the
hosts_cache, just use the host object from there.

When running a task on say 750 hosts, this yields a huge improvement.
11 years ago
James Cammarata ff04b2b532 Allow empty yaml vars files
Fixes #7843
11 years ago
Michael DeHaan c2ac8fda1e Data from inventory scripts should be able to use nested Jinja2 expressions. 11 years ago
James Cammarata 8ed6350e65 When parsing json from untrusted sources, remove templating tags 11 years ago
James Cammarata 539426f612 Performance tuning inventory functions for large inventories 11 years ago
James Cammarata d8a7b49b59 Merge branch 'inventorytree' of https://github.com/sergevanginderachter/ansible into sergevanginderachter-inventorytree 11 years ago
Kevin Bell 92bd755b47 Fixed extension filtering in InventoryDirectory 11 years ago
James Cammarata 393124e462 Add pyc/pyo to ignore list for inventory directories
Fixes #7308
11 years ago
Christian Berendt 6676720ce5 fixed typos found by RETF rules in PY files
rules are avaialble at https://en.wikipedia.org/wiki/Wikipedia:AutoWikiBrowser/Typos
11 years ago
Serge van Ginderachter e36e2d38fe InventoryDir: another fix for the host.groups list
In some cases, where a host is mentioned in multiple groups, and those
groups are referenced in multiple ini files, a group could still contain
multiple instances of a group in its host,groups list, where only one of them
is the right group, that exists in the inventory.
11 years ago
Cristian Ciupitu 96ff1444f0 Micro-optimization: replace s.find(x)==0 with s.startswith(x)
timeit shows a speedup of ~1.4x on Python 2.7.5 x86_64.
It also makes the code a bit shorter.
11 years ago
Serge van Ginderachter d4634983f0 Move group/host_vars parsing into core inventory
modified:   lib/ansible/inventory/__init__.py
	deleted:    lib/ansible/inventory/vars_plugins/group_vars.py
	modified:   lib/ansible/utils/__init__.py
11 years ago
Serge van Ginderachter f8ea93c732 Move inventory.set_playbook_basedir from ansible-playbook to playbook constructor 11 years ago
Serge van Ginderachter cc28fd891b Introduce noop vars plugin.
In preparation to move the group_vars plugin code into core.

	new file:   lib/ansible/inventory/vars_plugins/noop.py
11 years ago
Serge van Ginderachter f6a55a3552 Refactor vars_plugins (host/group_vars)
Split out parsing of vars files to per host and per group
parsing, instead of reparsing all groups for each host. This enhances
performance.

Extend vars_plugins' API with two new methods:
* get host variables: only parses host_vars
* get group variables: only parses group_vars for specific group
The initial run method is still used for backward compatibility.

Parse all vars_plugins at inventory initialisation, instead of
per host when touched first by runner. Here we can also loop through
all groups once easily, then parse them.
This also centralizes all parsing in the inventory constructor.

	modified:   bin/ansible
	modified:   bin/ansible-playbook
	modified:   lib/ansible/inventory/__init__.py
	modified:   lib/ansible/inventory/vars_plugins/group_vars.py
11 years ago
James Cammarata 846933dd53 Make inventory parsing error detection smarter
If something is executable but doesn't look like it should be, or if
something is NOT executable and DOES looks like it should, show a
more apropos error with a hint on correcting the problem

Fixes #5113
11 years ago
Serge van Ginderachter d3eaa1b79e InventoryDir: refactor logic
Make sure all hosts and groups are unique objects
and that those are referenced uniquely everywhere.
Also fixes test_dir_inventory unit tests which were broken after previous
patches.

	modified:   lib/ansible/inventory/dir.py
11 years ago
Serge van Ginderachter 188375171e Inventory: raise error when adding a group that already exists.
The parsers check if a group already exists.
11 years ago
Serge van Ginderachter be58808fe4 inventory script parser: do not add all the groups to *all* group 11 years ago
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
11 years ago
Serge van Ginderachter cc8efb4aab inventory groups: make sure group.depth is updated on all grandchildren 11 years ago
Serge van Ginderachter 1c86909875 inventory group: add groups to parent_groups only once 11 years ago
Serge van Ginderachter 36f55d3549 inventory directory parser: add host to group only once 11 years ago
Serge van Ginderachter 8b215149d4 inventory directory parser: add groups to parent_groups non-recursively 11 years ago
Serge van Ginderachter 262ba0460a inventory directory parser: add hosts to group non-recursively 11 years ago
Michael DeHaan 9da26da335 Merge branch 'ini_vars' of git://github.com/dmage/ansible into devel 11 years ago
Serge van Ginderachter 280498a7e5 Pass through vault_password when parsing host/group vars as directories.
Fixes a bug where vault_password parameter was not passed through in
_load_vars_from_folder()

modified:   lib/ansible/inventory/vars_plugins/group_vars.py
11 years ago
Michael DeHaan b41541c62a Merge conflict. 11 years ago
Michael DeHaan 4a06954a13 Merge pull request #6390 from sergevanginderachter/group-varsdirs-svn
group_vars plugin: do not parse hidden files in subfolders
11 years ago
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>
11 years ago
Michael DeHaan d5856bd475 Merge pull request #6391 from sergevanginderachter/hashmerge_inventoryscripts
Allow hash_behaviour=merge to be respected in core inventory
11 years ago
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.
11 years ago
Cristian Ciupitu a7da5d8702 Micro-optimization of inventory.expand_hosts.detect_range 11 years ago
Serge van Ginderachter 6b1cb22fc3 Allow hash_behaviour=merge to be respected in core inventory
(For now, this means, enable it also for inventory scripts)
11 years ago
Serge van Ginderachter 29c60bdaff group_vars plugin: do not parse hidden files in subfolders, e.g. avoid .svn/ 11 years ago
James Cammarata e3b887f770 Fix range issue in inventory and add additional error checking
Fixes #6331
11 years ago
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.
11 years ago
Michael DeHaan 94a7fb60fe Allow escaped comments in inventory files. 11 years ago
Richard C Isaacson b41d8106ff Revert "Merge pull request #6287 from risaacson/fix_hash_in_var"
This reverts commit a808287451, reversing
changes made to 6129ea7566.
11 years ago
Richard C Isaacson 38abd5e20e Break this out into a reusable function and document regex shortcomings. 11 years ago
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.
11 years ago
Jesse Keating 0c2c37a47a Avoid range selection on empty groups
This prevents a traceback when the group is empty.
Fixes #6258
11 years ago
James Cammarata f23ccebbdc Merge branch 'issue_4620' of https://github.com/jimi-c/ansible into jimi-c-issue_4620 11 years ago
James Tanner 427b8dc78d Ansible vault: a framework for encrypting any playbook or var file. 11 years ago
Ilya Kuznetsov 0658847ea6 Allow equal sign in single-line ini variables 11 years ago
James Cammarata ca0ec800d8 Revising method for parsing ranges from --limit subsets
Also added a new test (test_subset_range) for future validation.

Fixes #4620
11 years ago
jctanner a0f91f2aaa Merge pull request #5576 from xyrix/symlink-bug-fix
fixed bug causing symlinks to fail in the host_vars, group_vars etc dire...
11 years ago
James Cammarata f955d9db6a Handle implicit localhost when using '-i host,' syntax
Fixes #5820
11 years ago
Rob Smith 761fe8cc04 Fix an issue where git-pull fails with AttributeError
As part of 94f3b9bfab the code was changed to support dynamically adding localhost to the inventory. This change introduced an crash when run via ansible-pull

```
Starting ansible-pull at 2014-01-20 23:09:57
Traceback (most recent call last):
  File "/tmp/ansible/bin/ansible", line 157, in <module>
    (runner, results) = cli.run(options, args)
  File "/tmp/ansible/bin/ansible", line 82, in run
    hosts = inventory_manager.list_hosts(pattern)
  File "/tmp/ansible/lib/ansible/inventory/__init__.py", line 372, in list_hosts
    result = [ h.name for h in self.get_hosts(pattern) ]
  File "/tmp/ansible/lib/ansible/inventory/__init__.py", line 136, in get_hosts
    subset = self._get_hosts(self._subset)
  File "/tmp/ansible/lib/ansible/inventory/__init__.py", line 177, in _get_hosts
    that = self.__get_hosts(p)
  File "/tmp/ansible/lib/ansible/inventory/__init__.py", line 198, in __get_hosts
    hpat = self._hosts_in_unenumerated_pattern(name)
  File "/tmp/ansible/lib/ansible/inventory/__init__.py", line 275, in _hosts_in_unenumerated_pattern
    ungrouped.add_host(new_host)
AttributeError: 'NoneType' object has no attribute 'add_host'
```

The root cause is there is no group for the host to be added to. I fixed this case by creating the ungrouped group when it doesn't exist and then adding the host to the newly added group. This fixes the regression for me.
11 years ago
James Tanner 94f3b9bfab Fixes #3129 Do not require localhost to be in inventory 11 years ago
James Tanner 559e89036b Fixes #5631 Return a unique list of hosts when joining groups 11 years ago
jctanner 59d99c17b3 Merge pull request #5337 from bob-smith/bugfixFQDNParsing
Fix inventory parsing so that FQDN can be parsed without throwing ssh port error
11 years ago
jctanner a6bc63512e Merge pull request #5308 from zecrazytux/fix/hash_merge_dynamic_inventory
Let merge hash_bahaviour work with dynamic inventory
11 years ago
jay e1f5b801cf fixed bug causing symlinks to fail in the host_vars, group_vars etc directories 11 years ago
jctanner 21b4212ff5 Merge pull request #5517 from lichesser/fix_set_depreciation_warning
Fixes #5513. set is built-in since 2.4 and deprecated since 2.6
11 years ago
James Tanner ab51bd23a2 Fixes #5196 return a unique list of hostnames for a single host pattern 11 years ago
Michael DeHaan 227e8e31c9 Merge branch 'use_comps' of git://github.com/j2sol/ansible into devel 11 years ago
Michael DeHaan 10350d1639 Update various copyrights. Not complete, but sufficient. 11 years ago
Jesse Keating 23720ff19d Use list comprehensions for efficiency
For loops can be inefficient, particularly when doing a dot command with
them. https://wiki.python.org/moin/PythonSpeed/PerformanceTips#Loops and
https://wiki.python.org/moin/PythonSpeed/PerformanceTips#Avoiding_dots...

This patch makes use of list comprehensions to be as efficient as
possible while still retaining order. Efficiency was lost a bit when
switching away from sets() but this gains some of it back.
11 years ago
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
11 years ago
Sébastien Bocahu c8d5846ab9 Let merge hash_bahaviour work with dynamic inventory 11 years ago
Stoned Elipot b00bf02129 Improve Group.get_hosts() performance.
- reduce hosts group list to unique elements faster
- add a cache of already computed hosts group list
11 years ago
jctanner 0f0a89b34e Merge pull request #4758 from alanfairless/group-host-var-dirs
Support organizing group and host variables across multiple files in a directory
11 years ago
jctanner 9a7765daf7 Merge pull request #4351 from 2m/leading-range-fix
Allow leading ranges in the inventory host entries.
11 years ago
jctanner 0c29807ba3 Merge pull request #3993 from stoned/inventory-script-all-group-fix
Avoid duplicates of the 'all' group when using inventory script.
11 years ago
Alan Fairless 65e5331079 Allow organizing host/group vars in a directory
So instead of having:
 group_vars/production.yml

A user could chose to reorganize to:
 group_vars/production/staff.yml
 group_vars/production/networks.yml
 group_vars/production/dns.yml

(Backwards compatible.)
11 years ago
Alan Fairless babde9a84c refactor to catch edge cases, remove repeated code
- Move all the supported YAML file extensions into a constant
- Use helper functions to avoid duplicate code for group/host vars
- Catch and disallow some confusing situations, such as the presence of
  multiple group/host vars files for the same group/host, but with
  different extensions.  For example having both group_vars/all.yml and
  group_vars/all.yaml.
- Catch and report file system permission issues, symlink errors,
  unexpected file system objects
- Trivial performance improvement from making fewer stat system calls
- Restructuring that makes it easy for a following patch to support
  directory recursion
11 years ago
Michael DeHaan b5c9d5a59b Inventory directory should always be absolute. Fixes #4535. 11 years ago
Michael DeHaan c933a4c59a Fix indentation depth. 11 years ago
Martynas Mickevicius 7ecb5fbc9c Handle comment on inventory group line. 11 years ago
Martynas Mickevicius 44279ce34f Allow leading ranges in the inventory host entries. 11 years ago
Michael DeHaan 1b2d4c328c Cache patterns a bit higher up to make things a little more efficient. See #4469. 11 years ago
Michael DeHaan 41aaad69aa Make add_host clear the inventory pattern cache, add some more aliases. Fixes #4442. 11 years ago
Serge van Ginderachter c2e5f783da Add caching to pattern enumeration
Inventory._hosts_in_unenumerated_pattern()

Was TODO: cache this logic so if called a second time the result is not
recalculated
11 years ago
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
11 years ago
Michael DeHaan 8fc46a3a5a Return inventory objects in the order they are presented. Additionally, fix host slicing such that it works on Python terms with
zero indexed lists and a non-inclusive final element.
11 years ago
James Cammarata bff47df5ff Fix issue with ast evaluation of strings 11 years ago
Brian Coca 771435deb4 now ini vars are typed
Signed-off-by: Brian Coca <briancoca+dev@gmail.com>
11 years ago
Jasper Capel d4dec5f577 Allow creating empty inventory
Instantiating the Inventory class with host_list=None now results in an
empty inventory instead of an error.
11 years ago
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.
11 years ago
James Cammarata 39628d012d Minor fix to ipv6 detection for inventory with -i
For link-local addresses, it is sometimes necessary to append the
interface to use for the ipv6 address. This patch extends the ipv6
regex to allow for '%ifnameX' at the end.

See https://bugzilla.redhat.com/show_bug.cgi?id=136852 for more info
11 years ago
Michael Scherer c9d28e10ad add support for using a ipv6 in -i
testing with a ipv6 :
  ansible -u misc -i  '[2002::c23e]:22,' '*' -m ping

fail due to parsing of ':' as a separator of port/ip with ipv4.
This commit add support for properly parsing 2002::c23 and the
bracket notation [2002::ce]:2222
11 years ago
Matt Saunders 9fd1b174f5 Fixed tiny bug with _meta handling in external inventory scripts 11 years ago
ftao 51a180b150 fix inventory.basedir is not absolute path when hostfile is startswith "./" 11 years ago
Michael DeHaan ee11d69697 Merge branch 'better_ini_errors2' of git://github.com/bcoca/ansible into devel 11 years ago
René Moser e8272e365d
implemented 'inventory_file' variable. Closes GH-3789. 11 years ago
Serge van Ginderachter 40e60c947d Host specifiers should be sorted
to ensure consistent behavior, hosts should look like this:

    hosts: webservers:&boston:!rack42

So when applying the host selectors, run those without the "&" first,
then the &s, then the !s.

Closes #3500
11 years ago
Brian Coca a937a6a66d now bad ini entries will throw friendlier error
Signed-off-by: Brian Coca <briancoca+dev@gmail.com>
11 years ago
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
11 years ago
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.
11 years ago
Michael DeHaan 0335d05f43 Check against None around playbook basedir 11 years ago
Jonas Eriksson 16efb45735 Fix playbook-local host_vars when running from .
Since ansible 1.2, it became possible to place a host_vars
directory in the same directory as a playbook, making it possible
to keep host_vars local to that playbook there. However, due to
python's os.path.dirname, a action such as:

 $ ansible-playbook pb.yml

..would not pick up the host_vars as os.path.dirname("pb.yml")
returns "", unlike the unix command dirname that would return
".". Substituting "pb.yml" on the command line with "./pb.yml"
would do the trick, but is not always intuitive. This patch
solves the problem until python solves issue18547 [1].

[1] http://bugs.python.org/issue18547
11 years ago
Michael DeHaan 3baa55a314 Merge branch 'devel' of git://github.com/sjmudd/ansible into sjmudd_ranges 11 years ago
martin f. krafft fd02443d42 Enable negated patterns
A host pattern of the form '!foo' by itself does not work, but
'all:!foo' does. If the first pattern is a negation, this commit
automatically prepends 'all'.

Signed-off-by: martin f. krafft <madduck@madduck.net>
12 years ago
Rike-Benjamin Schuppner 71afb9e432 Use with guard for file reads. 12 years ago
Rike-Benjamin Schuppner deaf499ba1 Remove duplicate host file reads by removing a legacy check.
This allows using a form such as

    ansible -i <( arbitrary command ) all -m ping
12 years ago
Simon J Mudd 25822330a2 Add support for multiple ranges in a host
e.g.  db[01:10:3]node-[01:10]

- to do this we split off at the first [...] set, getting the list
  of hosts and then repeat until none left.
- also add an optional third parameter which contains the step. (Default: 1)
  so range can be [01:10:2] -> 01 03 05 07 09
12 years ago
Chris Jacobs 588d4080df don't want to ignore explicit cwd 12 years ago
Chris Jacobs 69db160e2f Skip dotfile in hosts dirs 12 years ago
Serge van Ginderachter f1cf81b086 optimization when adding child groups 12 years ago
Michael DeHaan c52abd40b0 Fix for the directory inventory source where depth information on the group was being discarded
due to initial copy.  New model will reuse the first object and copy attributes on the second.
12 years ago
Darryl Stoflet c0baf10845 Support for all:vars in script inventories 12 years ago
Michael DeHaan 1f7c197a9d os.path.dirname returns '' not None in some cases, handle this so inventory can be specified with ./ 12 years ago
Michael DeHaan 6cd3ba5b06 Allow the group_vars and host_vars directories to be stored alongside the playbook as well as inventory. 12 years ago
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.
12 years ago
Pol Llovet ba78360c52 Remove inline comments from inventory tokenizing. 12 years ago
Serge van Ginderachter 0c0d6c0b4e performance optimization in inventory.groups_list()
don't calculate all hosts for every parent group of every group
when that parent group was already in the cache
12 years ago
Nicolas Grilly 7aee588918 Idiomatic Python: use in operator instead of method find 12 years ago
Nicolas Grilly 7babd30cf7 Idiomatic Python: use isinstance instead of type 12 years ago
Serge van Ginderachter a6b827ca07 don't parse subdirs in host/group_vars
as those are not supported in
core vars_plugins/group_vars.py
but might be used by other vars_plugins
12 years ago
Michael DeHaan 50586928b2 No need for trailing semicolon. 12 years ago
Michael DeHaan e4e6616169 Merge pull request #2872 from tima/fuzzy-match-localhost-127
Adds fuzzy matching of localhost to 127.0.0.1 host entries and vice versa
12 years ago
Timothy Appnel 20bf5f130d Adds fuzzy matching of localhost to 127.0.0.1 host entries and vice versa. 12 years ago
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. 12 years ago
Michael DeHaan 5a8dff5bce Instantiate inventory plugins only once for efficiency reasons. 12 years ago
Michael DeHaan 87788b1d17 Ignore inventory config files when using an inventory directory. 12 years ago
Michael DeHaan d8bf87b008 (A) include errors in inventory scripts should they occur.
(B) allow registration with ignore_errors: True
12 years ago
Michael DeHaan 7c6341718e Merge branch 'combine_vars' of git://github.com/laggyluke/ansible into exp
Conflicts:
	lib/ansible/inventory/vars_plugins/group_vars.py
	lib/ansible/runner/__init__.py
	lib/ansible/utils/__init__.py
	test/TestPlayBook.py
12 years ago
C. Morgan Hamill 863cb50530 Allow '.yml'/'.yaml' extension on group_vars files.
Look for a file with the base name of the group/host, first without
a file extension, then with a '.yml' extension, and, finally, with
a '.yaml' extension, loading vars from only the first one found.
12 years ago
Michael DeHaan 29209c4913 Style fixes so "make pep8" is clean. 12 years ago
Michael DeHaan 0d530f3bf0 Change the retry logic to write a limit file, able to source limit from files by indicating with @filename 12 years ago
Michael DeHaan c695aa2d6a When playbooks fail, attempt to create an inventory file in the inventory directory that allows rerunning
of the playbook against only the hosts that failed.
12 years ago
George Miroshnykov 6826aa7360 Tweaked merge_hash to also affect Runner behavior 12 years ago
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.
12 years ago
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
12 years ago
Stoned Elipot 86995d7786 Fix pathnames in comments 12 years ago
Rob Parrott 149f1f9f3c invalidate group cache so that a group added by the add_host module will be relfected in the groups variable in later plays. 12 years ago
Daniel Hokka Zakrisson 1784fd80cc When a host list is used, no parser is present 12 years ago
Daniel Hokka Zakrisson 2ff2f05a0f host.get_variables includes too many variables, use host.vars instead
Not quite as attractive, but allows variable precedence and lazy
resolution to work as intended, rather than resolving them on a
per-inventory basis.
12 years ago
Daniel Hokka Zakrisson f1eb195ff5 vars_loader should get the path to the inventory + vars_plugins 12 years ago
Daniel Hokka Zakrisson ad08995989 Make inventory basedir for directory based inventory be the directory
This puts host_vars and group_vars inside of the directory, allowing you
to target a single inventory but still have access to the variables.
12 years ago
Daniel Hokka Zakrisson d9c6b60b24 Allow inventory to be a directory containing other inventories 12 years ago
Daniel Hokka Zakrisson 647cd0141c Move all inventory script code into the script parser 12 years ago
Nigel Metheringham c0e28762f0 Allow end of line comments in inventory file
See github issue 2702
https://github.com/ansible/ansible/issues/2072
12 years ago
Michael DeHaan 0ad6ac4086 Fix group depth for nested groups 12 years ago
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).
12 years ago
Brian Coca ca5f52b825 now missing hosts file gives nice message and no traceback
Signed-off-by: Brian Coca <briancoca+dev@gmail.com>
12 years ago
Daniel Hokka Zakrisson 6f9099c51d Merge pull request #1898 from silviud/fix_inventory_list_groups
Inventory class - lambda fails on attribute access - g.name is a string not the group obje...
12 years ago
Michel Blanc e28e538c6e Adds user-selectable hash merging support in vars
Hash variables are currently overriden if they are redefined. This
doesn't let the user refine hash entries or overriding selected keys,
which can, for some, be a desirable feature.
This patch let the user force hash merging by setting the
hash_behaviour value to "merge" (without the quotes) in ansible.cfg

However, by default, ansible behaves like it always did and if any value
besides "merge" is used ("replace" is suggested in the example ansible.cfg
file), it will also behave as always.
12 years ago
Silviu Dicu f7694ac433 lambda fails on attribute access - g.name is a string not the group object 12 years ago
Daniel Hokka Zakrisson c23eda82c2 Allow pattern[0] to address a single node
Replaces erroring out on it and requiring the abysmal pattern[0-0]
instead.
12 years ago
Michael DeHaan 04195e202d Merge pull request #1747 from njharman/alpharange
Alphabetic inventory hostname patterns.
12 years ago
Michael DeHaan 4bcdd24688 Merge pull request #1776 from junegunn/inventory-group-var-ws
Allows whitespaces around assignment operators when defining group variables
12 years ago
Junegunn Choi 8896486606 Adds comments on handling quoted group vars 12 years ago
Junegunn Choi 7fbb7e079a Fix hostname expansion bug in inventory parser 12 years ago
Junegunn Choi daf797804b Allows whitespaces around assignment operators
when defining group variables
12 years ago
Michael DeHaan 70bb7d1e54 Merge pull request #1696 from gregorg/enhance_limit
Allow regex to be used to select hosts in addition to fnmatch pattern
12 years ago
Daniel Hokka Zakrisson 54b45e9bd4 Allow intersecting host patterns by using &
This allows patterns such as webservers:!debian:&datacenter1 to target
hosts in the webservers group, that are not in the debian group, but are
in the datacenter1 group. It also parses patterns left to right.
12 years ago
Norman J. Harman Jr 6603737e4d Alphabetic inventory hostname patterns.
- Code, docs, tests.
  - Also added test of large range 000-142 to verify alpha range did not
    break this.
12 years ago
Daniel Hokka Zakrisson 8d309e0fa3 Allow inventory scripts to define groups of groups and group vars 12 years ago
Gregory Duchatelet dde01dabc3 Squashed commit of the following:
commit 48069adf0f
Author: Gregory Duchatelet <skygreg@gmail.com>
Date:   Tue Nov 27 10:13:08 2012 +0100

    Removing this plugin from this branch.

commit 15400fffe6
Author: Gregory Duchatelet <skygreg@gmail.com>
Date:   Tue Nov 27 09:53:16 2012 +0100

    Enhance _match function in inventory with regex.
    --limit ~regex could be used to filter hosts or group with a regex.
    Tested on cli and ansible-playbook.

commit 63c1b2e17e
Author: Gregory Duchatelet <skygreg@gmail.com>
Date:   Tue Nov 27 09:03:41 2012 +0100

    Revert pull request #1684

commit 7c2c6fee3a
Merge: f023a2f dd5a847
Author: Gregory Duchatelet <skygreg@gmail.com>
Date:   Tue Nov 27 08:52:53 2012 +0100

    Merge remote branch 'upstream/devel' into devel

commit f023a2f3df
Author: Gregory Duchatelet <skygreg@gmail.com>
Date:   Mon Nov 26 20:52:27 2012 +0100

    Add an inventory plugin to fetch groups and host from our CMDB.

commit c64193b4c6
Author: Gregory Duchatelet <skygreg@gmail.com>
Date:   Mon Nov 26 20:43:30 2012 +0100

    Added possibility to filter hosts from a group, with a regex, separating
    groupname and regex with a ~
    Usage in group pattern: group~filterpattern
    Samples:
    ansible group~server-0[1236] -m ping
    ansible web~proxy -m ping
    ansible web~(proxy|frontend) -m ping
12 years ago
Daniel Hokka Zakrisson 0c70abfaa9 Make sure any existing groups gets reused 12 years ago
Daniel Hokka Zakrisson 5504f13c68 Create groups in the first run through the file
Fixes #1208.
12 years ago
Daniel Hokka Zakrisson 2bfb7deec0 Set all in the returned dict
Otherwise the group is lost, and group_vars/all isn't used.
12 years ago
Daniel Hokka Zakrisson 715d875dcb Group should only return its own variables
Otherwise, a host in two groups, A and B, using a variable defined
in group A and all will get the value of all, as B's variables will
include the all variable.

Partially fixes #1647.
12 years ago
Daniel Hokka Zakrisson bd7e02d629 Get all groups' variables in order of depth
Fixes all not being processed, as well as the order of the variable
precedence
12 years ago
Daniel Hokka Zakrisson 5dd2ec2cae Add a way to add directories to just one type of loader 12 years ago
Daniel Hokka Zakrisson 17e4ce97a4 Create a set of all the hosts in a group to prevent duplicates
Fixes #1516.
12 years ago
Dag Wieers c9e62d7061 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.

This is in line with the change from #1535
12 years ago
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.
12 years ago
Daniel Hokka Zakrisson e05e514861 Create a plugin loader system 12 years ago
Michael DeHaan c0747b7baa pep8 fixes 12 years ago
Michael DeHaan 9a12873166 Merge pull request #1477 from skvidal/devel
add check that vars plugins are not handing back None
12 years ago
Seth Vidal 3fcc591f18 add check that vars plugins are not handing back None 12 years ago
Dag Wieers 3728b2f459 Missing errors-import causes traceback 12 years ago
Michael DeHaan 6ba30170dd Make group_vars and host_vars available to usr/bin/ansible, and make vars_plugins exist 12 years ago
Seth Vidal d63fa6f026 make --limit take a , as a separator as well as ; or : 12 years ago
Daniel Hokka Zakrisson b8021f12e0 Raise error for missing hosts in inventory scripts as well 12 years ago
Michael DeHaan a69e59ab2b Allows delegate_to to use inventory host/port info. 12 years ago
Jeroen Hoekx 23a62f5a78 Return multiple groups from inventory API. 12 years ago
Peter Sankauskas 8a4e969b93 Getting negative host pattern matching to work with external inventory
(same as commit 4caf85e37b, but for
excluded hosts as well as subsets)
12 years ago
Michael Lambert 29ac1a8efc Replace os.access with stat calls for determining the executability of a given path. 12 years ago
Michael DeHaan 58ad934283 Merge pull request #1024 from tima/groups-pb
Made $groups and $group_names variables accessible in with_items
12 years ago
John Kleint 1f8696f5c1 Fix inventory.get_hosts when hosts is a list. 12 years ago
Timothy Appnel 20fc6a29d3 Made groups.groupname and group_names variables accessible in playbooks. 12 years ago
Michael DeHaan f140332ff6 Make it possible in the inventory file to have spaces in host variables 12 years ago
Michael DeHaan 4caf85e37b Fix --limit for external inventory scripts, slight variant on fix from pull #949 12 years ago
Michael DeHaan 898d7676f7 Adds the 'serial' keyword to a playbook which controls how many hosts can be running through a playbook at a single time.
The default is 0, which means all hosts.  If set to 1, each host would run a playbook all the way through before moving
on the next host.  Fact gathering is still parallel, regardless of the serial setting.
12 years ago
Michael DeHaan 6de8c27085 Load parent groups when processing group_vars 12 years ago
Michael DeHaan 9041adddaa Add support for ranged patterns like webservers[0-49] for hitting the first 50 webservers. 12 years ago
Michael DeHaan 72faf8eb0a fix indents 12 years ago
Michael DeHaan d1ad1d2508 remove stray print 12 years ago
Michael DeHaan 259f2dc4de Various retooling of the internal code behind inventory pattern matching in support of pending support
for host ranges.
12 years ago
Michael DeHaan 1c81ddf8d4 add the limit option, which can be used to further confine the patterns selected by "hosts:" in ansible-playbooks
to an additional pattern (a subset) specified on the command line.  For instance, a playbook could be reusable
and target "webservers" and "dbservers", but you want to test only in the stage environment, or a few boxes at a time.
12 years ago
Dave Peticolas 08272dc25d Remove unused imports. 12 years ago
Michael DeHaan faed4b5a33 whitespace + remove deprecated YAML parser (migration script lives in examples/scripts and warning was added
in 0.6 release)
12 years ago
Ahmad Khayyat 6728b6cdda Allow = symbols in variable values in host inventory 12 years ago
Michael DeHaan da44fb1e43 Fixes #731 by reinstating variables for inventory scripts 12 years ago
Peter Sankauskas 0188889aea Making inventory pattern matching handle group names 12 years ago
Derek Carter 547395a2be added inventory_hostname_short varible 12 years ago
Michael DeHaan 82cca242e3 use AnsibleError so that if there is an error it does not print a traceback 12 years ago
Michael DeHaan 8fa4dc3920 Small change to previous patch, make ranges of hosts inclusive. 12 years ago
Chin Fang 5315dd146d Added lib/ansible/inventory/expand_hosts.py 12 years ago
Chin Fang e3b2521f01 Added a host expansion feature to ansible's inventory parsing 12 years ago
Michael DeHaan 617f9dc942 Added some caching logic to improve external inventory scripts, removed some debug statements. 12 years ago
Michael DeHaan 57f12ac9e3 Using __slots__ in more places, in particular, hosts and groups, where we are apt to create a fair amount of objects. 12 years ago
Michael DeHaan 5a67a556cd Script to migrate YAML users to the INI format, so we can deprecate YAML inventory (which we are now doing). 13 years ago
Michael DeHaan ba3466af95 The following paths are now implict and optional in vars_files:
./group_vars/groupname.yml (for all groups the host is in)
./host_vars/hostname.yml (for the hostname given in the inventory)

This requires an actual inventory file, not script and the paths are relative
to the directory of the inventory file.
13 years ago
Seth Vidal 5ad9bc8833 when using -i"hostname," on the cli - don't complain about the host named "" not being a host - just clip it from the list 13 years ago
Michael DeHaan 1754de3335 Misc code cleanup, mostly whitespace preferences, removing unused imports, plus a few fixes here and there. 13 years ago
Michael DeHaan 1d8bb17785 misc code cleanup 13 years ago
Michael DeHaan 68a9adc1be Indentation cleanup (partial) 13 years ago
Michael DeHaan 60f295f7a0 Squashed commit of the following:
commit 4430ce3eefcdff0b0ceffea0ef66ea8e876a807d
Merge: 631783b 649963c
Author: Michael DeHaan <michael.dehaan@gmail.com>
Date:   Thu Jul 12 01:28:43 2012 -0400

    Merge branch 'host-groups' of https://github.com/dagwieers/ansible into daggroups

commit 649963ca2c
Author: Dag Wieërs <dag@wieers.com>
Date:   Thu Jul 12 23:01:00 2012 +0200

    Added comments in the example yaml file as requested

commit 7f9718f185
Author: Dag Wieërs <dag@wieers.com>
Date:   Thu Jul 12 22:49:38 2012 +0200

    Add the default nose color too, to test specific overrides

commit eb63b9e899
Author: Dag Wieërs <dag@wieers.com>
Date:   Thu Jul 12 22:44:35 2012 +0200

    Introduce comics and cartoons to test yaml groups defined on a per-node basis

commit aa13d23307
Author: Dag Wieërs <dag@wieers.com>
Date:   Thu Jul 12 19:33:15 2012 +0200

    A small fix to revert to old state

commit 264ebaa77c
Author: Dag Wieërs <dag@wieers.com>
Date:   Thu Jul 12 19:31:51 2012 +0200

    Combine both yaml unit tests into one example file

commit 7db49a8048
Author: Dag Wieërs <dag@wieers.com>
Date:   Thu Jul 12 16:46:53 2012 +0200

    Might as well fix this too

commit f36c6c8c5b
Author: Dag Wieërs <dag@wieers.com>
Date:   Thu Jul 12 16:42:00 2012 +0200

    Added unit tests for host-groups patch

    For the unit test I chose to keep the original yaml file in place as a reference.

    This patch also includes a fix.

commit a96f681352
Author: Dag Wieërs <dag@wieers.com>
Date:   Thu Jul 12 12:30:43 2012 +0200

    Allow groups to be defined on a per-host basis

    This makes it possible to define on a per-host basis what groups a host is in.
    When managing a large set of systems it makes it easier to ensure each of the
    systems is defined in a set of groups (e.g. production/qa/development,
    linux/solaris/aix) rather than having to add systems to multiple disconnected
    groups.

    ----
      - host: system01

      - host: system02

      - host: system03

      - group: linux
        hosts:
        - system01
        - system02

      - group: solaris
        hosts:
        - system03

      - group: production
        hosts:
        - system01
        - system03

      - group: qa
        - system02

      - group: dbserver
        hosts:
        - system01

      - group: ntpserver
        hosts:
        - system02

      - group: webserver
        - system03
    ----

    Can be redefined as:

    ----
      - host: system01
        groups: [ linux, production, dbserver ]

      - host: system02
        groups: [ linux, qa, ntpserver ]

      - host: system03
        groups: [ solaris, production, webserver ]
    ----
13 years ago
Jeroen Hoekx d592e15dcc Correctly add ungrouped hosts to 'ungrouped' in YAML inventory. 13 years ago
Daniel Hokka Zakrisson 3d5c93bf44 Allow exclusion of hosts/groups 13 years ago
Brad Olson 81591009ea Fixed Inventory.get_hosts() ignoring restriction when there are no hosts left.
get_hosts() was treating [] (meaning complete restriction, no hosts allowed)
the same as None (meaning no restriction, all hosts allowed). Fixed logic.
13 years ago
Michael DeHaan cf9ddf3a30 Reorganizing file structure. Not done. 13 years ago