Inventory: raise error when adding a group that already exists.

The parsers check if a group already exists.
pull/4420/head
Serge van Ginderachter 2014-03-10 13:06:04 +01:00
parent be58808fe4
commit 188375171e
1 changed files with 5 additions and 3 deletions

View File

@ -16,7 +16,6 @@
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
############################################# #############################################
import fnmatch import fnmatch
import os import os
import sys import sys
@ -376,8 +375,11 @@ class Inventory(object):
return vars return vars
def add_group(self, group): def add_group(self, group):
self.groups.append(group) if group.name not in self.groups_list():
self._groups_list = None # invalidate internal cache self.groups.append(group)
self._groups_list = None # invalidate internal cache
else:
raise errors.AnsibleError("group already in inventory: %s" % group.name)
def list_hosts(self, pattern="all"): def list_hosts(self, pattern="all"):