From daab8e7ad487444ee9f8511e3f8f898413d232a9 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Thu, 2 Oct 2014 12:07:05 -0500 Subject: [PATCH] Creating initial framework for refactoring core codebase --- lib/v2/__init__.py | 19 ++++++ lib/v2/cache/__init__.py | 17 +++++ lib/v2/config/__init__.py | 17 +++++ lib/v2/errors/__init__.py | 19 ++++++ lib/v2/inventory/__init__.py | 26 ++++++++ lib/v2/inventory/group.py | 44 +++++++++++++ lib/v2/inventory/host.py | 27 ++++++++ lib/v2/inventory/loaders/__init__.py | 17 +++++ lib/v2/inventory/loaders/dir.py | 17 +++++ lib/v2/inventory/loaders/ini.py | 17 +++++ lib/v2/inventory/loaders/script.py | 17 +++++ lib/v2/inventory/pattern.py | 36 +++++++++++ lib/v2/modules/__init__.py | 17 +++++ lib/v2/modules/docs/__init__.py | 17 +++++ lib/v2/modules/docs/fragments/__init__.py | 17 +++++ lib/v2/modules/utils/__init__.py | 17 +++++ lib/v2/playbook/__init__.py | 30 +++++++++ lib/v2/playbook/base.py | 28 ++++++++ lib/v2/playbook/block.py | 30 +++++++++ lib/v2/playbook/conditional.py | 78 +++++++++++++++++++++++ lib/v2/playbook/handler.py | 39 ++++++++++++ lib/v2/playbook/play.py | 17 +++++ lib/v2/playbook/playbook_include.py | 17 +++++ lib/v2/playbook/role.py | 55 ++++++++++++++++ lib/v2/playbook/tag.py | 45 +++++++++++++ lib/v2/playbook/task.py | 38 +++++++++++ lib/v2/playbook/task_include.py | 17 +++++ lib/v2/plugins/__init__.py | 17 +++++ lib/v2/plugins/action/__init__.py | 17 +++++ lib/v2/plugins/callback/__init__.py | 17 +++++ lib/v2/plugins/connections/__init__.py | 17 +++++ lib/v2/plugins/filter/__init__.py | 17 +++++ lib/v2/plugins/inventory/__init__.py | 17 +++++ lib/v2/plugins/lookup/__init__.py | 17 +++++ lib/v2/plugins/shell/__init__.py | 17 +++++ lib/v2/plugins/vars/__init__.py | 17 +++++ lib/v2/runner/__init__.py | 36 +++++++++++ lib/v2/utils/__init__.py | 17 +++++ 38 files changed, 941 insertions(+) create mode 100644 lib/v2/__init__.py create mode 100644 lib/v2/cache/__init__.py create mode 100644 lib/v2/config/__init__.py create mode 100644 lib/v2/errors/__init__.py create mode 100644 lib/v2/inventory/__init__.py create mode 100644 lib/v2/inventory/group.py create mode 100644 lib/v2/inventory/host.py create mode 100644 lib/v2/inventory/loaders/__init__.py create mode 100644 lib/v2/inventory/loaders/dir.py create mode 100644 lib/v2/inventory/loaders/ini.py create mode 100644 lib/v2/inventory/loaders/script.py create mode 100644 lib/v2/inventory/pattern.py create mode 100644 lib/v2/modules/__init__.py create mode 100644 lib/v2/modules/docs/__init__.py create mode 100644 lib/v2/modules/docs/fragments/__init__.py create mode 100644 lib/v2/modules/utils/__init__.py create mode 100644 lib/v2/playbook/__init__.py create mode 100644 lib/v2/playbook/base.py create mode 100644 lib/v2/playbook/block.py create mode 100644 lib/v2/playbook/conditional.py create mode 100644 lib/v2/playbook/handler.py create mode 100644 lib/v2/playbook/play.py create mode 100644 lib/v2/playbook/playbook_include.py create mode 100644 lib/v2/playbook/role.py create mode 100644 lib/v2/playbook/tag.py create mode 100644 lib/v2/playbook/task.py create mode 100644 lib/v2/playbook/task_include.py create mode 100644 lib/v2/plugins/__init__.py create mode 100644 lib/v2/plugins/action/__init__.py create mode 100644 lib/v2/plugins/callback/__init__.py create mode 100644 lib/v2/plugins/connections/__init__.py create mode 100644 lib/v2/plugins/filter/__init__.py create mode 100644 lib/v2/plugins/inventory/__init__.py create mode 100644 lib/v2/plugins/lookup/__init__.py create mode 100644 lib/v2/plugins/shell/__init__.py create mode 100644 lib/v2/plugins/vars/__init__.py create mode 100644 lib/v2/runner/__init__.py create mode 100644 lib/v2/utils/__init__.py diff --git a/lib/v2/__init__.py b/lib/v2/__init__.py new file mode 100644 index 00000000000..05b82a40c7e --- /dev/null +++ b/lib/v2/__init__.py @@ -0,0 +1,19 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +__version__ = '1.8' +__author__ = 'Michael DeHaan' diff --git a/lib/v2/cache/__init__.py b/lib/v2/cache/__init__.py new file mode 100644 index 00000000000..d6c11ffa742 --- /dev/null +++ b/lib/v2/cache/__init__.py @@ -0,0 +1,17 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + diff --git a/lib/v2/config/__init__.py b/lib/v2/config/__init__.py new file mode 100644 index 00000000000..d6c11ffa742 --- /dev/null +++ b/lib/v2/config/__init__.py @@ -0,0 +1,17 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + diff --git a/lib/v2/errors/__init__.py b/lib/v2/errors/__init__.py new file mode 100644 index 00000000000..8b250383d50 --- /dev/null +++ b/lib/v2/errors/__init__.py @@ -0,0 +1,19 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +class AnsibleError(Exception): + pass diff --git a/lib/v2/inventory/__init__.py b/lib/v2/inventory/__init__.py new file mode 100644 index 00000000000..29c9a8324d3 --- /dev/null +++ b/lib/v2/inventory/__init__.py @@ -0,0 +1,26 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +class Inventory(object): + def __init__(self): + pass + + def get_hosts(self): + return [] + + def get_groups(self): + return [] diff --git a/lib/v2/inventory/group.py b/lib/v2/inventory/group.py new file mode 100644 index 00000000000..9a277178f4b --- /dev/null +++ b/lib/v2/inventory/group.py @@ -0,0 +1,44 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +class Group(object): + def __init__(self, name, hosts=[]): + self.name = name + self.hosts = hosts + self.parents = [] + self.children = [] + + def get_vars(self): + return dict() + + def get_hosts(self): + return self.hosts + + def get_direct_subgroups(self): + direct_children = [] + for child in self.children: + direct_children.append(child.name) + return direct_children + + def get_all_subgroups(self): + all_children = [] + for child in self.children: + all_children.extend(child.get_all_subgroups()) + return all_children + + def get_parent_groups(self): + return self.parents diff --git a/lib/v2/inventory/host.py b/lib/v2/inventory/host.py new file mode 100644 index 00000000000..390f0f87449 --- /dev/null +++ b/lib/v2/inventory/host.py @@ -0,0 +1,27 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +class Host(object): + def __init__(self, name): + self.name = name + self.groups = [] + + def get_vars(self): + return dict() + + def get_groups(self): + return self.groups diff --git a/lib/v2/inventory/loaders/__init__.py b/lib/v2/inventory/loaders/__init__.py new file mode 100644 index 00000000000..d6c11ffa742 --- /dev/null +++ b/lib/v2/inventory/loaders/__init__.py @@ -0,0 +1,17 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + diff --git a/lib/v2/inventory/loaders/dir.py b/lib/v2/inventory/loaders/dir.py new file mode 100644 index 00000000000..d6c11ffa742 --- /dev/null +++ b/lib/v2/inventory/loaders/dir.py @@ -0,0 +1,17 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + diff --git a/lib/v2/inventory/loaders/ini.py b/lib/v2/inventory/loaders/ini.py new file mode 100644 index 00000000000..d6c11ffa742 --- /dev/null +++ b/lib/v2/inventory/loaders/ini.py @@ -0,0 +1,17 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + diff --git a/lib/v2/inventory/loaders/script.py b/lib/v2/inventory/loaders/script.py new file mode 100644 index 00000000000..d6c11ffa742 --- /dev/null +++ b/lib/v2/inventory/loaders/script.py @@ -0,0 +1,17 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + diff --git a/lib/v2/inventory/pattern.py b/lib/v2/inventory/pattern.py new file mode 100644 index 00000000000..dd7068bdbc7 --- /dev/null +++ b/lib/v2/inventory/pattern.py @@ -0,0 +1,36 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +from v2.inventory import Host, Group + +class HostPattern(object): + def __init__(self, pattern): + self.pattern = pattern + + def match(thing): + ''' + return a list of matches + ''' + + matches = [] + if isinstance(thing, Host): + # simple match against a single host + pass + elif isinstance(thing, Group): + # match against the list of hosts in the group + pass + return matches diff --git a/lib/v2/modules/__init__.py b/lib/v2/modules/__init__.py new file mode 100644 index 00000000000..d6c11ffa742 --- /dev/null +++ b/lib/v2/modules/__init__.py @@ -0,0 +1,17 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + diff --git a/lib/v2/modules/docs/__init__.py b/lib/v2/modules/docs/__init__.py new file mode 100644 index 00000000000..d6c11ffa742 --- /dev/null +++ b/lib/v2/modules/docs/__init__.py @@ -0,0 +1,17 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + diff --git a/lib/v2/modules/docs/fragments/__init__.py b/lib/v2/modules/docs/fragments/__init__.py new file mode 100644 index 00000000000..d6c11ffa742 --- /dev/null +++ b/lib/v2/modules/docs/fragments/__init__.py @@ -0,0 +1,17 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + diff --git a/lib/v2/modules/utils/__init__.py b/lib/v2/modules/utils/__init__.py new file mode 100644 index 00000000000..d6c11ffa742 --- /dev/null +++ b/lib/v2/modules/utils/__init__.py @@ -0,0 +1,17 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + diff --git a/lib/v2/playbook/__init__.py b/lib/v2/playbook/__init__.py new file mode 100644 index 00000000000..0671c261ff9 --- /dev/null +++ b/lib/v2/playbook/__init__.py @@ -0,0 +1,30 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +import v2.utils + +class Playbook(object): + def __init__(self, filename): + self.ds = v2.utils.load_yaml_from_file(filename) + self.plays = [] + + def load(self): + # loads a list of plays from the parsed ds + self.plays = [] + + def get_plays(self): + return self.plays diff --git a/lib/v2/playbook/base.py b/lib/v2/playbook/base.py new file mode 100644 index 00000000000..44abe4a6ea3 --- /dev/null +++ b/lib/v2/playbook/base.py @@ -0,0 +1,28 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +from v2.playbook import Tag, Conditional + +class PlaybookBase(Tag, Conditional): + ''' + Implements a common object, which supports filtering based on + both tags and when: conditional statements + ''' + + def __init__(self): + pass + diff --git a/lib/v2/playbook/block.py b/lib/v2/playbook/block.py new file mode 100644 index 00000000000..f4d5946135d --- /dev/null +++ b/lib/v2/playbook/block.py @@ -0,0 +1,30 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +from v2.playbook.base import PlaybookBase + +class Block(PlaybookBase): + def __init__(self): + self.ds = None + self.plays = [] + + def load(self, ds): + self.ds = ds + self.plays = [] + + def get_plays(self): + return self.plays diff --git a/lib/v2/playbook/conditional.py b/lib/v2/playbook/conditional.py new file mode 100644 index 00000000000..f12a1eb218f --- /dev/null +++ b/lib/v2/playbook/conditional.py @@ -0,0 +1,78 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +import v2.config as C +from v2.utils import template +from v2.utils import list_union + +class Conditional(object): + def __init__(self, basedir, conditionals=[]): + self.basedir = basedir + self.conditionals = conditionals + + def push(self, conditional): + if conditional not in self.conditionals: + self.conditionals.append(conditional) + + def get_conditionals(self): + # return a full slice to make sure the reference + # doesn't get mangled by other users of the result + return self.conditionals[:] + + def merge(self, conditional): + if isinstance(conditional, basestring): + conditional = Conditional(self.basedir, [conditional]) + elif isinstance(conditional, list): + conditional = Conditional(self.basedir, conditional) + elif not isinstance(conditional, Conditional): + raise AnsibleError('expected a Conditional() class, instead got a %s' % type(conditional)) + self.conditionals = list_union(self.conditionals, conditional.get_conditonals()) + + def evaluate(self, inject): + for conditional in self.conditional: + if not self._do_evaluate(conditional, inject): + return False + return True + + def _do_evaluate(self, conditional, inject): + # allow variable names + if conditional in inject and '-' not in str(inject[conditional]): + conditional = inject[conditional] + conditional = template.template(self.basedir, conditional, inject, fail_on_undefined=C.fail_on_undefined) + original = str(conditional).replace("jinja2_compare ","") + # a Jinja2 evaluation that results in something Python can eval! + presented = "{%% if %s %%} True {%% else %%} False {%% endif %%}" % conditional + conditional = template.template(self.basedir, presented, inject) + val = conditional.strip() + if val == presented: + # the templating failed, meaning most likely a + # variable was undefined. If we happened to be + # looking for an undefined variable, return True, + # otherwise fail + if "is undefined" in conditional: + return True + elif "is defined" in conditional: + return False + else: + raise errors.AnsibleError("error while evaluating conditional: %s" % original) + elif val == "True": + return True + elif val == "False": + return False + else: + raise errors.AnsibleError("unable to evaluate conditional: %s" % original) + diff --git a/lib/v2/playbook/handler.py b/lib/v2/playbook/handler.py new file mode 100644 index 00000000000..32a803dbc52 --- /dev/null +++ b/lib/v2/playbook/handler.py @@ -0,0 +1,39 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +from v2.errors import AnsibleError +from v2.inventory import Host +from v2.playbook import Task + +class Handler(Task): + def __init__(self): + self.triggered = False + self.triggered_by = [] + + def flag_for_host(self, host): + if not isinstance(host, Host): + raise AnsibleError('handlers expected to be triggered by a Host(), instead got %s' % type(host)) + if host.name not in self.triggered_by: + triggered_by.append(host.name) + + def get_has_triggered(self): + return self.triggered + + def set_has_triggered(self, triggered): + if not isinstance(triggered, bool): + raise AnsibleError('a handlers triggered property should be a boolean, instead got %s' % type(triggered)) + self.triggered = triggered diff --git a/lib/v2/playbook/play.py b/lib/v2/playbook/play.py new file mode 100644 index 00000000000..d6c11ffa742 --- /dev/null +++ b/lib/v2/playbook/play.py @@ -0,0 +1,17 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + diff --git a/lib/v2/playbook/playbook_include.py b/lib/v2/playbook/playbook_include.py new file mode 100644 index 00000000000..d6c11ffa742 --- /dev/null +++ b/lib/v2/playbook/playbook_include.py @@ -0,0 +1,17 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + diff --git a/lib/v2/playbook/role.py b/lib/v2/playbook/role.py new file mode 100644 index 00000000000..80251833d06 --- /dev/null +++ b/lib/v2/playbook/role.py @@ -0,0 +1,55 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +from v2.playbook.base import PlaybookBase +from v2.utils import list_union + +class Role(PlaybookBase): + def __init__(self): + pass + + def load(self, ds): + self.ds = ds + self.tasks = [] + self.handlers = [] + self.blocks = [] + self.dependencies = [] + self.metadata = dict() + self.defaults = dict() + self.vars = dict() + self.params = dict() + + def get_vars(self): + # returns the merged variables for this role, including + # recursively merging those of all child roles + return dict() + + def get_immediate_dependencies(self): + return self.dependencies + + def get_all_dependencies(self): + # returns a list built recursively, of all deps from + # all child dependencies + all_deps = [] + for dep in self.dependencies: + list_union(all_deps, dep.get_all_dependencies()) + all_deps = list_union(all_deps, self.dependencies) + return all_deps + + def get_blocks(self): + # should return + return self.blocks diff --git a/lib/v2/playbook/tag.py b/lib/v2/playbook/tag.py new file mode 100644 index 00000000000..239038ea884 --- /dev/null +++ b/lib/v2/playbook/tag.py @@ -0,0 +1,45 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +from v2.errors import AnsibleError +from v2.utils import list_union + +class Tag(object): + def __init__(self, tags=[]): + self.tags = tags + + def push(self, tag): + if tag not in self.tags: + self.tags.append(tag) + + def get_tags(self): + return self.tags + + def merge(self, tags): + # returns a union of the tags, which can be a string, + # a list of strings, or another Tag() class + if isinstance(tags, basestring): + tags = Tag([tags]) + elif isinstance(tags, list): + tags = Tag(tags) + elif not isinstance(tags, Tag): + raise AnsibleError('expected a Tag() instance, instead got %s' % type(tags)) + return utils.list_union(self.tags, tags.get_tags()) + + def matches(self, tag): + return tag in self.tags + diff --git a/lib/v2/playbook/task.py b/lib/v2/playbook/task.py new file mode 100644 index 00000000000..2979ba21465 --- /dev/null +++ b/lib/v2/playbook/task.py @@ -0,0 +1,38 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +from v2.playbook.base import PlaybookBase + +class Task(PlaybookBase): + def __init__(self, block=None, role=None): + self.ds = None + self.block = block + self.role = role + + def load(self, ds): + self.ds = ds + self.name = "" + + def get_vars(self): + return dict() + + def get_role(self): + return self.role + + def get_block(self): + return self.block + diff --git a/lib/v2/playbook/task_include.py b/lib/v2/playbook/task_include.py new file mode 100644 index 00000000000..d6c11ffa742 --- /dev/null +++ b/lib/v2/playbook/task_include.py @@ -0,0 +1,17 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + diff --git a/lib/v2/plugins/__init__.py b/lib/v2/plugins/__init__.py new file mode 100644 index 00000000000..d6c11ffa742 --- /dev/null +++ b/lib/v2/plugins/__init__.py @@ -0,0 +1,17 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + diff --git a/lib/v2/plugins/action/__init__.py b/lib/v2/plugins/action/__init__.py new file mode 100644 index 00000000000..d6c11ffa742 --- /dev/null +++ b/lib/v2/plugins/action/__init__.py @@ -0,0 +1,17 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + diff --git a/lib/v2/plugins/callback/__init__.py b/lib/v2/plugins/callback/__init__.py new file mode 100644 index 00000000000..d6c11ffa742 --- /dev/null +++ b/lib/v2/plugins/callback/__init__.py @@ -0,0 +1,17 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + diff --git a/lib/v2/plugins/connections/__init__.py b/lib/v2/plugins/connections/__init__.py new file mode 100644 index 00000000000..d6c11ffa742 --- /dev/null +++ b/lib/v2/plugins/connections/__init__.py @@ -0,0 +1,17 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + diff --git a/lib/v2/plugins/filter/__init__.py b/lib/v2/plugins/filter/__init__.py new file mode 100644 index 00000000000..d6c11ffa742 --- /dev/null +++ b/lib/v2/plugins/filter/__init__.py @@ -0,0 +1,17 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + diff --git a/lib/v2/plugins/inventory/__init__.py b/lib/v2/plugins/inventory/__init__.py new file mode 100644 index 00000000000..d6c11ffa742 --- /dev/null +++ b/lib/v2/plugins/inventory/__init__.py @@ -0,0 +1,17 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + diff --git a/lib/v2/plugins/lookup/__init__.py b/lib/v2/plugins/lookup/__init__.py new file mode 100644 index 00000000000..d6c11ffa742 --- /dev/null +++ b/lib/v2/plugins/lookup/__init__.py @@ -0,0 +1,17 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + diff --git a/lib/v2/plugins/shell/__init__.py b/lib/v2/plugins/shell/__init__.py new file mode 100644 index 00000000000..d6c11ffa742 --- /dev/null +++ b/lib/v2/plugins/shell/__init__.py @@ -0,0 +1,17 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + diff --git a/lib/v2/plugins/vars/__init__.py b/lib/v2/plugins/vars/__init__.py new file mode 100644 index 00000000000..d6c11ffa742 --- /dev/null +++ b/lib/v2/plugins/vars/__init__.py @@ -0,0 +1,17 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + diff --git a/lib/v2/runner/__init__.py b/lib/v2/runner/__init__.py new file mode 100644 index 00000000000..2e60a96faa8 --- /dev/null +++ b/lib/v2/runner/__init__.py @@ -0,0 +1,36 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +from v2.inventory import Host +from v2.playbook import Task + +class Runner(object): + def __init__(self, host, task): + self.host = host + self.task = task + self.action = self.get_action() + + def get_action(self): + # returns the action plugin from plugins/action/ + # for the given task + return None + + def execute(self): + # runs the given task on the given host using + # the action determined by get_action() + return + diff --git a/lib/v2/utils/__init__.py b/lib/v2/utils/__init__.py new file mode 100644 index 00000000000..d6c11ffa742 --- /dev/null +++ b/lib/v2/utils/__init__.py @@ -0,0 +1,17 @@ +# (c) 2012-2014, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . +