Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9a0695
commit a098a8e
Showing
14 changed files
with
161 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Test ability to import playbooks.""" | ||
from ansiblelint.runner import Runner | ||
|
||
|
||
def test_local_collection(default_rules_collection): | ||
"""Assures local collections are found.""" | ||
playbook_path = 'test/local-content/test-collection.yml' | ||
runner = Runner(default_rules_collection, playbook_path, [], [], []) | ||
results = runner.run() | ||
|
||
assert len(runner.playbooks) == 1 | ||
assert len(results) == 0 | ||
|
||
|
||
def test_roles_local_content(default_rules_collection): | ||
"""Assures local content in roles is found.""" | ||
playbook_path = 'test/local-content/test-roles-success.yml' | ||
runner = Runner(default_rules_collection, playbook_path, [], [], []) | ||
results = runner.run() | ||
|
||
assert len(runner.playbooks) == 1 | ||
assert len(results) == 0 | ||
|
||
|
||
def test_roles_local_content_failure(default_rules_collection): | ||
"""Assures local content in roles is found, even if Ansible itself has trouble.""" | ||
playbook_path = 'test/local-content/test-roles-failure.yml' | ||
runner = Runner(default_rules_collection, playbook_path, [], [], []) | ||
results = runner.run() | ||
|
||
assert len(runner.playbooks) == 1 | ||
assert len(results) == 0 | ||
|
||
|
||
def test_roles_local_content_failure_complete(default_rules_collection): | ||
"""Role with local content that is not found.""" | ||
playbook_path = 'test/local-content/test-roles-failure-complete.yml' | ||
runner = Runner(default_rules_collection, playbook_path, [], [], []) | ||
results = runner.run() | ||
|
||
assert len(runner.playbooks) == 1 | ||
assert len(results) == 0 |
3 changes: 3 additions & 0 deletions
3
test/local-content/collections/ansible_collections/testns/testcoll/galaxy.yml
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,3 @@ | ||
namespace: testns | ||
name: testcoll | ||
version: 0.1.0 |
15 changes: 15 additions & 0 deletions
15
...cal-content/collections/ansible_collections/testns/testcoll/plugins/filter/test_filter.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"""A filter plugin.""" | ||
|
||
def test_filter(a, b): | ||
"""Test filter.""" | ||
return '{0}:{1}'.format(a, b) | ||
|
||
|
||
class FilterModule(object): | ||
"""Filter plugin.""" | ||
|
||
def filters(self): | ||
"""Return filters.""" | ||
return { | ||
'test_filter': test_filter | ||
} |
12 changes: 12 additions & 0 deletions
12
...-content/collections/ansible_collections/testns/testcoll/plugins/modules/test_module_2.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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/python | ||
"""A module.""" | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
|
||
def main(): | ||
"""Module code.""" | ||
module = AnsibleModule(dict()) | ||
module.exit_json(msg="Hello 2!") | ||
|
||
if __name__ == '__main__': | ||
main() |
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,12 @@ | ||
#!/usr/bin/python | ||
"""A module.""" | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
|
||
def main(): | ||
"""Module code.""" | ||
module = AnsibleModule(dict()) | ||
module.exit_json(msg="Hello 1!") | ||
|
||
if __name__ == '__main__': | ||
main() |
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,3 @@ | ||
--- | ||
- name: Use local module 1 | ||
test_module_1: |
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,11 @@ | ||
--- | ||
- name: Use local module from other role that has been included before this one | ||
# If it has not been included before, loading this role fails! | ||
test_module_1: | ||
- name: Use local module from other role that has been included before this one | ||
# If it has not been included before, loading this role fails! | ||
test_module_3: | ||
- name: Use local test plugin | ||
assert: | ||
that: | ||
- "'2' is b_test '12345'" |
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,19 @@ | ||
"""A test plugin.""" | ||
|
||
from __future__ import (absolute_import, division, print_function) | ||
__metaclass__ = type | ||
|
||
|
||
def compatibility_in_test(a, b): | ||
"""Simple 'in' test.""" | ||
return a in b | ||
|
||
|
||
class TestModule: | ||
"""Test plugin.""" | ||
|
||
def tests(self): | ||
"""Return tests.""" | ||
return { | ||
'b_test': compatibility_in_test, | ||
} |
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,12 @@ | ||
#!/usr/bin/python | ||
"""A module.""" | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
|
||
def main(): | ||
"""Module code.""" | ||
module = AnsibleModule(dict()) | ||
module.exit_json(msg="Hello 3!") | ||
|
||
if __name__ == '__main__': | ||
main() |
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,3 @@ | ||
--- | ||
- name: Use local module 3 | ||
test_module_3: |
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,10 @@ | ||
--- | ||
- name: Use module and filter plugin from local collection | ||
hosts: localhost | ||
tasks: | ||
- name: Use module from local collection | ||
testns.testcoll.test_module_2: | ||
- name: Use filter from local collection | ||
assert: | ||
that: | ||
- 1 | testns.testcoll.test_filter(2) == '1:2' |
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 @@ | ||
--- | ||
- name: Include role which expects module that is local to other role which is not loaded | ||
hosts: localhost | ||
roles: | ||
- role2 |
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,7 @@ | ||
--- | ||
- name: Use roles with local module in wrong order, so that Ansible fails | ||
hosts: localhost | ||
roles: | ||
- role2 | ||
- role3 | ||
- role1 |
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,7 @@ | ||
--- | ||
- name: Use roles with local modules and test plugins | ||
hosts: localhost | ||
roles: | ||
- role1 | ||
- role3 | ||
- role2 |