From deaf499ba1635673eb7259008a19a77bc16d04e7 Mon Sep 17 00:00:00 2001 From: Rike-Benjamin Schuppner Date: Mon, 10 Jun 2013 15:51:35 +0200 Subject: [PATCH 1/2] Remove duplicate host file reads by removing a legacy check. This allows using a form such as ansible -i <( arbitrary command ) all -m ping --- lib/ansible/inventory/__init__.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/ansible/inventory/__init__.py b/lib/ansible/inventory/__init__.py index 17e501f1431..d5df2f89d92 100644 --- a/lib/ansible/inventory/__init__.py +++ b/lib/ansible/inventory/__init__.py @@ -90,12 +90,8 @@ class Inventory(object): self.parser = InventoryScript(filename=host_list) self.groups = self.parser.groups.values() else: - data = file(host_list).read() - if not data.startswith("---"): - self.parser = InventoryParser(filename=host_list) - self.groups = self.parser.groups.values() - else: - raise errors.AnsibleError("YAML inventory support is deprecated in 0.6 and removed in 0.7, see the migration script in examples/scripts in the git checkout") + self.parser = InventoryParser(filename=host_list) + self.groups = self.parser.groups.values() utils.plugins.vars_loader.add_directory(self.basedir(), with_subdir=True) else: From 71afb9e43213b86cef9748469fa225dd10342548 Mon Sep 17 00:00:00 2001 From: Rike-Benjamin Schuppner Date: Mon, 10 Jun 2013 15:52:04 +0200 Subject: [PATCH 2/2] Use with guard for file reads. --- lib/ansible/inventory/ini.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/ansible/inventory/ini.py b/lib/ansible/inventory/ini.py index 8412f4acac5..1c7ae58bf15 100644 --- a/lib/ansible/inventory/ini.py +++ b/lib/ansible/inventory/ini.py @@ -33,11 +33,11 @@ class InventoryParser(object): def __init__(self, filename=C.DEFAULT_HOST_LIST): - fh = open(filename) - self.lines = fh.readlines() - self.groups = {} - self.hosts = {} - self._parse() + with open(filename) as fh: + self.lines = fh.readlines() + self.groups = {} + self.hosts = {} + self._parse() def _parse(self):