-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from dellis23/steenzout-ansible20
added support for Ansible 2.0
- Loading branch information
Showing
11 changed files
with
112 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from .dao import create_dao | ||
|
||
DaoImpl = create_dao() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import ansible | ||
|
||
|
||
class AnsibleDao(object): | ||
""" | ||
Interface for Ansible Data Access Object implementation. | ||
""" | ||
|
||
def __init__(self): | ||
self.version = ansible.__version__ | ||
|
||
def get_vault_lib(self): | ||
""" | ||
Returns the Ansible VaultLib class. | ||
""" | ||
raise NotImplementedError | ||
|
||
def read_vault_file(vault_password_file): | ||
""" | ||
Read a vault password from a file or if executable, | ||
execute the script and | ||
retrieve password from STDOUT | ||
""" | ||
raise NotImplementedError | ||
|
||
|
||
class Ansible2(AnsibleDao): | ||
""" | ||
Ansible 2.x implementation. | ||
""" | ||
|
||
def __init__(self): | ||
if not ansible.__version__.startswith('2'): | ||
raise NotImplementedError( | ||
'Cannot use Ansible 2.x implementation with Ansible 1.x!') | ||
|
||
def get_vault_lib(self): | ||
from ansible.parsing.vault import VaultLib | ||
return VaultLib | ||
|
||
def read_vault_file(self, vault_password_file): | ||
from ansible.cli import CLI | ||
from ansible.parsing.dataloader import DataLoader | ||
|
||
return CLI.read_vault_password_file(vault_password_file, DataLoader()) | ||
|
||
|
||
class Ansible1(AnsibleDao): | ||
""" | ||
Ansible 1.x implementation. | ||
""" | ||
|
||
def __init__(self): | ||
if not ansible.__version__.startswith('1'): | ||
raise NotImplementedError( | ||
'Cannot use Ansible 1.x implementation with Ansible 2.x!') | ||
|
||
def get_vault_lib(self): | ||
from ansible.utils.vault import VaultLib | ||
return VaultLib | ||
|
||
def read_vault_file(self, vault_password_file): | ||
from ansible.utils import read_vault_file | ||
return read_vault_file(vault_password_file) | ||
|
||
|
||
def create_dao(): | ||
""" | ||
Creates an Ansible data access object implementation that | ||
implements the dao.AnsibleDao interface. | ||
:return: Ansible data access object. | ||
""" | ||
|
||
if ansible.__version__.startswith('2'): | ||
return Ansible2() | ||
return Ansible1() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
|
||
class MalformedGitDiff(Exception): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from ansible.runner import Runner | ||
from ansible.utils.template import template_from_file | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from ansible.runner import Runner | ||
from ansible.utils import combine_vars, template | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
ansible_toolkit/tests/git_diff_test.py → tests/git_diff_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import tempfile | ||
import unittest | ||
|
||
|