From 8a754e0858d922e955e71b253c139e071ecec432 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 18:04:21 +0200 Subject: Adding upstream version 2.14.3. Signed-off-by: Daniel Baumann --- test/integration/targets/module_precedence/aliases | 2 + .../module_precedence/lib_no_extension/ping | 71 ++++++++++++++++++++++ .../module_precedence/lib_with_extension/a.ini | 13 ++++ .../module_precedence/lib_with_extension/a.py | 13 ++++ .../module_precedence/lib_with_extension/ping.ini | 13 ++++ .../module_precedence/lib_with_extension/ping.py | 71 ++++++++++++++++++++++ .../targets/module_precedence/modules_test.yml | 10 +++ .../module_precedence/modules_test_envvar.yml | 11 ++++ .../module_precedence/modules_test_envvar_ext.yml | 16 +++++ .../modules_test_multiple_roles.yml | 17 ++++++ .../modules_test_multiple_roles_reverse_order.yml | 16 +++++ .../module_precedence/modules_test_role.yml | 13 ++++ .../module_precedence/modules_test_role_ext.yml | 18 ++++++ .../multiple_roles/bar/library/ping.py | 71 ++++++++++++++++++++++ .../multiple_roles/bar/tasks/main.yml | 10 +++ .../multiple_roles/foo/library/ping.py | 71 ++++++++++++++++++++++ .../multiple_roles/foo/tasks/main.yml | 10 +++ .../roles_no_extension/foo/library/ping | 71 ++++++++++++++++++++++ .../roles_no_extension/foo/tasks/main.yml | 10 +++ .../roles_with_extension/foo/library/a.ini | 13 ++++ .../roles_with_extension/foo/library/a.py | 13 ++++ .../roles_with_extension/foo/library/ping.ini | 13 ++++ .../roles_with_extension/foo/library/ping.py | 71 ++++++++++++++++++++++ .../roles_with_extension/foo/tasks/main.yml | 10 +++ .../integration/targets/module_precedence/runme.sh | 49 +++++++++++++++ 25 files changed, 696 insertions(+) create mode 100644 test/integration/targets/module_precedence/aliases create mode 100644 test/integration/targets/module_precedence/lib_no_extension/ping create mode 100644 test/integration/targets/module_precedence/lib_with_extension/a.ini create mode 100644 test/integration/targets/module_precedence/lib_with_extension/a.py create mode 100644 test/integration/targets/module_precedence/lib_with_extension/ping.ini create mode 100644 test/integration/targets/module_precedence/lib_with_extension/ping.py create mode 100644 test/integration/targets/module_precedence/modules_test.yml create mode 100644 test/integration/targets/module_precedence/modules_test_envvar.yml create mode 100644 test/integration/targets/module_precedence/modules_test_envvar_ext.yml create mode 100644 test/integration/targets/module_precedence/modules_test_multiple_roles.yml create mode 100644 test/integration/targets/module_precedence/modules_test_multiple_roles_reverse_order.yml create mode 100644 test/integration/targets/module_precedence/modules_test_role.yml create mode 100644 test/integration/targets/module_precedence/modules_test_role_ext.yml create mode 100644 test/integration/targets/module_precedence/multiple_roles/bar/library/ping.py create mode 100644 test/integration/targets/module_precedence/multiple_roles/bar/tasks/main.yml create mode 100644 test/integration/targets/module_precedence/multiple_roles/foo/library/ping.py create mode 100644 test/integration/targets/module_precedence/multiple_roles/foo/tasks/main.yml create mode 100644 test/integration/targets/module_precedence/roles_no_extension/foo/library/ping create mode 100644 test/integration/targets/module_precedence/roles_no_extension/foo/tasks/main.yml create mode 100644 test/integration/targets/module_precedence/roles_with_extension/foo/library/a.ini create mode 100644 test/integration/targets/module_precedence/roles_with_extension/foo/library/a.py create mode 100644 test/integration/targets/module_precedence/roles_with_extension/foo/library/ping.ini create mode 100644 test/integration/targets/module_precedence/roles_with_extension/foo/library/ping.py create mode 100644 test/integration/targets/module_precedence/roles_with_extension/foo/tasks/main.yml create mode 100755 test/integration/targets/module_precedence/runme.sh (limited to 'test/integration/targets/module_precedence') diff --git a/test/integration/targets/module_precedence/aliases b/test/integration/targets/module_precedence/aliases new file mode 100644 index 0000000..8278ec8 --- /dev/null +++ b/test/integration/targets/module_precedence/aliases @@ -0,0 +1,2 @@ +shippable/posix/group3 +context/controller diff --git a/test/integration/targets/module_precedence/lib_no_extension/ping b/test/integration/targets/module_precedence/lib_no_extension/ping new file mode 100644 index 0000000..a28f469 --- /dev/null +++ b/test/integration/targets/module_precedence/lib_no_extension/ping @@ -0,0 +1,71 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# (c) 2012, Michael DeHaan +# (c) 2016, Toshio Kuratomi +# +# 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 __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ['stableinterface'], + 'supported_by': 'core'} + + +DOCUMENTATION = ''' +--- +module: ping +version_added: historical +short_description: Try to connect to host, verify a usable python and return C(pong) on success. +description: + - A trivial test module, this module always returns C(pong) on successful + contact. It does not make sense in playbooks, but it is useful from + C(/usr/bin/ansible) to verify the ability to login and that a usable python is configured. + - This is NOT ICMP ping, this is just a trivial test module. +options: {} +author: + - "Ansible Core Team" + - "Michael DeHaan" +''' + +EXAMPLES = ''' +# Test we can logon to 'webservers' and execute python with json lib. +ansible webservers -m ping +''' + +from ansible.module_utils.basic import AnsibleModule + + +def main(): + module = AnsibleModule( + argument_spec=dict( + data=dict(required=False, default=None), + ), + supports_check_mode=True + ) + result = dict(ping='pong') + if module.params['data']: + if module.params['data'] == 'crash': + raise Exception("boom") + result['ping'] = module.params['data'] + result['location'] = 'library' + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/test/integration/targets/module_precedence/lib_with_extension/a.ini b/test/integration/targets/module_precedence/lib_with_extension/a.ini new file mode 100644 index 0000000..80278c9 --- /dev/null +++ b/test/integration/targets/module_precedence/lib_with_extension/a.ini @@ -0,0 +1,13 @@ +#!/usr/bin/python +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import json + + +def main(): + print(json.dumps(dict(changed=False, location='a.ini'))) + + +if __name__ == '__main__': + main() diff --git a/test/integration/targets/module_precedence/lib_with_extension/a.py b/test/integration/targets/module_precedence/lib_with_extension/a.py new file mode 100644 index 0000000..8eda141 --- /dev/null +++ b/test/integration/targets/module_precedence/lib_with_extension/a.py @@ -0,0 +1,13 @@ +#!/usr/bin/python +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import json + + +def main(): + print(json.dumps(dict(changed=False, location='a.py'))) + + +if __name__ == '__main__': + main() diff --git a/test/integration/targets/module_precedence/lib_with_extension/ping.ini b/test/integration/targets/module_precedence/lib_with_extension/ping.ini new file mode 100644 index 0000000..6f4b6a1 --- /dev/null +++ b/test/integration/targets/module_precedence/lib_with_extension/ping.ini @@ -0,0 +1,13 @@ +#!/usr/bin/python +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import json + + +def main(): + print(json.dumps(dict(changed=False, location='ping.ini'))) + + +if __name__ == '__main__': + main() diff --git a/test/integration/targets/module_precedence/lib_with_extension/ping.py b/test/integration/targets/module_precedence/lib_with_extension/ping.py new file mode 100644 index 0000000..a28f469 --- /dev/null +++ b/test/integration/targets/module_precedence/lib_with_extension/ping.py @@ -0,0 +1,71 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# (c) 2012, Michael DeHaan +# (c) 2016, Toshio Kuratomi +# +# 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 __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ['stableinterface'], + 'supported_by': 'core'} + + +DOCUMENTATION = ''' +--- +module: ping +version_added: historical +short_description: Try to connect to host, verify a usable python and return C(pong) on success. +description: + - A trivial test module, this module always returns C(pong) on successful + contact. It does not make sense in playbooks, but it is useful from + C(/usr/bin/ansible) to verify the ability to login and that a usable python is configured. + - This is NOT ICMP ping, this is just a trivial test module. +options: {} +author: + - "Ansible Core Team" + - "Michael DeHaan" +''' + +EXAMPLES = ''' +# Test we can logon to 'webservers' and execute python with json lib. +ansible webservers -m ping +''' + +from ansible.module_utils.basic import AnsibleModule + + +def main(): + module = AnsibleModule( + argument_spec=dict( + data=dict(required=False, default=None), + ), + supports_check_mode=True + ) + result = dict(ping='pong') + if module.params['data']: + if module.params['data'] == 'crash': + raise Exception("boom") + result['ping'] = module.params['data'] + result['location'] = 'library' + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/test/integration/targets/module_precedence/modules_test.yml b/test/integration/targets/module_precedence/modules_test.yml new file mode 100644 index 0000000..cf3e888 --- /dev/null +++ b/test/integration/targets/module_precedence/modules_test.yml @@ -0,0 +1,10 @@ +- hosts: testhost + gather_facts: no + tasks: + - name: Use standard ping module + ping: + register: result + + - assert: + that: + - '"location" not in result' diff --git a/test/integration/targets/module_precedence/modules_test_envvar.yml b/test/integration/targets/module_precedence/modules_test_envvar.yml new file mode 100644 index 0000000..f52e2f9 --- /dev/null +++ b/test/integration/targets/module_precedence/modules_test_envvar.yml @@ -0,0 +1,11 @@ +- hosts: testhost + gather_facts: no + tasks: + - name: Use ping from library path + ping: + register: result + + - assert: + that: + - '"location" in result' + - 'result["location"] == "library"' diff --git a/test/integration/targets/module_precedence/modules_test_envvar_ext.yml b/test/integration/targets/module_precedence/modules_test_envvar_ext.yml new file mode 100644 index 0000000..48f27c4 --- /dev/null +++ b/test/integration/targets/module_precedence/modules_test_envvar_ext.yml @@ -0,0 +1,16 @@ +- hosts: testhost + gather_facts: no + tasks: + - name: Use ping from library path + ping: + register: result + + - name: Use a from library path + a: + register: a_res + + - assert: + that: + - '"location" in result' + - 'result["location"] == "library"' + - 'a_res["location"] == "a.py"' diff --git a/test/integration/targets/module_precedence/modules_test_multiple_roles.yml b/test/integration/targets/module_precedence/modules_test_multiple_roles.yml new file mode 100644 index 0000000..f4bd264 --- /dev/null +++ b/test/integration/targets/module_precedence/modules_test_multiple_roles.yml @@ -0,0 +1,17 @@ +- hosts: testhost + gather_facts: no + vars: + expected_location: "role: foo" + roles: + - foo + - bar + + tasks: + - name: Use ping from role + ping: + register: result + + - assert: + that: + - '"location" in result' + - 'result["location"] == "{{ expected_location}}"' diff --git a/test/integration/targets/module_precedence/modules_test_multiple_roles_reverse_order.yml b/test/integration/targets/module_precedence/modules_test_multiple_roles_reverse_order.yml new file mode 100644 index 0000000..5403ae2 --- /dev/null +++ b/test/integration/targets/module_precedence/modules_test_multiple_roles_reverse_order.yml @@ -0,0 +1,16 @@ +- hosts: testhost + gather_facts: no + vars: + expected_location: "role: bar" + roles: + - bar + - foo + tasks: + - name: Use ping from role + ping: + register: result + + - assert: + that: + - '"location" in result' + - 'result["location"] == "{{ expected_location}}"' diff --git a/test/integration/targets/module_precedence/modules_test_role.yml b/test/integration/targets/module_precedence/modules_test_role.yml new file mode 100644 index 0000000..ccbe31d --- /dev/null +++ b/test/integration/targets/module_precedence/modules_test_role.yml @@ -0,0 +1,13 @@ +- hosts: testhost + gather_facts: no + roles: + - foo + tasks: + - name: Use ping from role + ping: + register: result + + - assert: + that: + - '"location" in result' + - 'result["location"] == "role: foo"' diff --git a/test/integration/targets/module_precedence/modules_test_role_ext.yml b/test/integration/targets/module_precedence/modules_test_role_ext.yml new file mode 100644 index 0000000..f8816f9 --- /dev/null +++ b/test/integration/targets/module_precedence/modules_test_role_ext.yml @@ -0,0 +1,18 @@ +- hosts: testhost + gather_facts: no + roles: + - foo + tasks: + - name: Use ping from role + ping: + register: result + + - name: Use from role + a: + register: a_res + + - assert: + that: + - '"location" in result' + - 'result["location"] == "role: foo"' + - 'a_res["location"] == "role: foo, a.py"' diff --git a/test/integration/targets/module_precedence/multiple_roles/bar/library/ping.py b/test/integration/targets/module_precedence/multiple_roles/bar/library/ping.py new file mode 100644 index 0000000..98ef7b4 --- /dev/null +++ b/test/integration/targets/module_precedence/multiple_roles/bar/library/ping.py @@ -0,0 +1,71 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# (c) 2012, Michael DeHaan +# (c) 2016, Toshio Kuratomi +# +# 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 __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ['stableinterface'], + 'supported_by': 'core'} + + +DOCUMENTATION = ''' +--- +module: ping +version_added: historical +short_description: Try to connect to host, verify a usable python and return C(pong) on success. +description: + - A trivial test module, this module always returns C(pong) on successful + contact. It does not make sense in playbooks, but it is useful from + C(/usr/bin/ansible) to verify the ability to login and that a usable python is configured. + - This is NOT ICMP ping, this is just a trivial test module. +options: {} +author: + - "Ansible Core Team" + - "Michael DeHaan" +''' + +EXAMPLES = ''' +# Test we can logon to 'webservers' and execute python with json lib. +ansible webservers -m ping +''' + +from ansible.module_utils.basic import AnsibleModule + + +def main(): + module = AnsibleModule( + argument_spec=dict( + data=dict(required=False, default=None), + ), + supports_check_mode=True + ) + result = dict(ping='pong') + if module.params['data']: + if module.params['data'] == 'crash': + raise Exception("boom") + result['ping'] = module.params['data'] + result['location'] = 'role: bar' + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/test/integration/targets/module_precedence/multiple_roles/bar/tasks/main.yml b/test/integration/targets/module_precedence/multiple_roles/bar/tasks/main.yml new file mode 100644 index 0000000..52c3402 --- /dev/null +++ b/test/integration/targets/module_precedence/multiple_roles/bar/tasks/main.yml @@ -0,0 +1,10 @@ +--- +- name: Use ping from inside foo role + ping: + register: result + +- name: Make sure that we used the ping module from the foo role + assert: + that: + - '"location" in result' + - 'result["location"] == "{{ expected_location }}"' diff --git a/test/integration/targets/module_precedence/multiple_roles/foo/library/ping.py b/test/integration/targets/module_precedence/multiple_roles/foo/library/ping.py new file mode 100644 index 0000000..8860b7a --- /dev/null +++ b/test/integration/targets/module_precedence/multiple_roles/foo/library/ping.py @@ -0,0 +1,71 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# (c) 2012, Michael DeHaan +# (c) 2016, Toshio Kuratomi +# +# 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 __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ['stableinterface'], + 'supported_by': 'core'} + + +DOCUMENTATION = ''' +--- +module: ping +version_added: historical +short_description: Try to connect to host, verify a usable python and return C(pong) on success. +description: + - A trivial test module, this module always returns C(pong) on successful + contact. It does not make sense in playbooks, but it is useful from + C(/usr/bin/ansible) to verify the ability to login and that a usable python is configured. + - This is NOT ICMP ping, this is just a trivial test module. +options: {} +author: + - "Ansible Core Team" + - "Michael DeHaan" +''' + +EXAMPLES = ''' +# Test we can logon to 'webservers' and execute python with json lib. +ansible webservers -m ping +''' + +from ansible.module_utils.basic import AnsibleModule + + +def main(): + module = AnsibleModule( + argument_spec=dict( + data=dict(required=False, default=None), + ), + supports_check_mode=True + ) + result = dict(ping='pong') + if module.params['data']: + if module.params['data'] == 'crash': + raise Exception("boom") + result['ping'] = module.params['data'] + result['location'] = 'role: foo' + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/test/integration/targets/module_precedence/multiple_roles/foo/tasks/main.yml b/test/integration/targets/module_precedence/multiple_roles/foo/tasks/main.yml new file mode 100644 index 0000000..52c3402 --- /dev/null +++ b/test/integration/targets/module_precedence/multiple_roles/foo/tasks/main.yml @@ -0,0 +1,10 @@ +--- +- name: Use ping from inside foo role + ping: + register: result + +- name: Make sure that we used the ping module from the foo role + assert: + that: + - '"location" in result' + - 'result["location"] == "{{ expected_location }}"' diff --git a/test/integration/targets/module_precedence/roles_no_extension/foo/library/ping b/test/integration/targets/module_precedence/roles_no_extension/foo/library/ping new file mode 100644 index 0000000..8860b7a --- /dev/null +++ b/test/integration/targets/module_precedence/roles_no_extension/foo/library/ping @@ -0,0 +1,71 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# (c) 2012, Michael DeHaan +# (c) 2016, Toshio Kuratomi +# +# 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 __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ['stableinterface'], + 'supported_by': 'core'} + + +DOCUMENTATION = ''' +--- +module: ping +version_added: historical +short_description: Try to connect to host, verify a usable python and return C(pong) on success. +description: + - A trivial test module, this module always returns C(pong) on successful + contact. It does not make sense in playbooks, but it is useful from + C(/usr/bin/ansible) to verify the ability to login and that a usable python is configured. + - This is NOT ICMP ping, this is just a trivial test module. +options: {} +author: + - "Ansible Core Team" + - "Michael DeHaan" +''' + +EXAMPLES = ''' +# Test we can logon to 'webservers' and execute python with json lib. +ansible webservers -m ping +''' + +from ansible.module_utils.basic import AnsibleModule + + +def main(): + module = AnsibleModule( + argument_spec=dict( + data=dict(required=False, default=None), + ), + supports_check_mode=True + ) + result = dict(ping='pong') + if module.params['data']: + if module.params['data'] == 'crash': + raise Exception("boom") + result['ping'] = module.params['data'] + result['location'] = 'role: foo' + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/test/integration/targets/module_precedence/roles_no_extension/foo/tasks/main.yml b/test/integration/targets/module_precedence/roles_no_extension/foo/tasks/main.yml new file mode 100644 index 0000000..985fc34 --- /dev/null +++ b/test/integration/targets/module_precedence/roles_no_extension/foo/tasks/main.yml @@ -0,0 +1,10 @@ +--- +- name: Use ping from inside foo role + ping: + register: result + +- name: Make sure that we used the ping module from the foo role + assert: + that: + - '"location" in result' + - 'result["location"] == "role: foo"' diff --git a/test/integration/targets/module_precedence/roles_with_extension/foo/library/a.ini b/test/integration/targets/module_precedence/roles_with_extension/foo/library/a.ini new file mode 100644 index 0000000..8b17029 --- /dev/null +++ b/test/integration/targets/module_precedence/roles_with_extension/foo/library/a.ini @@ -0,0 +1,13 @@ +#!/usr/bin/python +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import json + + +def main(): + print(json.dumps(dict(changed=False, location='role: foo, a.ini'))) + + +if __name__ == '__main__': + main() diff --git a/test/integration/targets/module_precedence/roles_with_extension/foo/library/a.py b/test/integration/targets/module_precedence/roles_with_extension/foo/library/a.py new file mode 100644 index 0000000..4bc5906 --- /dev/null +++ b/test/integration/targets/module_precedence/roles_with_extension/foo/library/a.py @@ -0,0 +1,13 @@ +#!/usr/bin/python +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import json + + +def main(): + print(json.dumps(dict(changed=False, location='role: foo, a.py'))) + + +if __name__ == '__main__': + main() diff --git a/test/integration/targets/module_precedence/roles_with_extension/foo/library/ping.ini b/test/integration/targets/module_precedence/roles_with_extension/foo/library/ping.ini new file mode 100644 index 0000000..f9c04f5 --- /dev/null +++ b/test/integration/targets/module_precedence/roles_with_extension/foo/library/ping.ini @@ -0,0 +1,13 @@ +#!/usr/bin/python +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import json + + +def main(): + print(json.dumps(dict(changed=False, location='role: foo, ping.ini'))) + + +if __name__ == '__main__': + main() diff --git a/test/integration/targets/module_precedence/roles_with_extension/foo/library/ping.py b/test/integration/targets/module_precedence/roles_with_extension/foo/library/ping.py new file mode 100644 index 0000000..8860b7a --- /dev/null +++ b/test/integration/targets/module_precedence/roles_with_extension/foo/library/ping.py @@ -0,0 +1,71 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# (c) 2012, Michael DeHaan +# (c) 2016, Toshio Kuratomi +# +# 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 __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ['stableinterface'], + 'supported_by': 'core'} + + +DOCUMENTATION = ''' +--- +module: ping +version_added: historical +short_description: Try to connect to host, verify a usable python and return C(pong) on success. +description: + - A trivial test module, this module always returns C(pong) on successful + contact. It does not make sense in playbooks, but it is useful from + C(/usr/bin/ansible) to verify the ability to login and that a usable python is configured. + - This is NOT ICMP ping, this is just a trivial test module. +options: {} +author: + - "Ansible Core Team" + - "Michael DeHaan" +''' + +EXAMPLES = ''' +# Test we can logon to 'webservers' and execute python with json lib. +ansible webservers -m ping +''' + +from ansible.module_utils.basic import AnsibleModule + + +def main(): + module = AnsibleModule( + argument_spec=dict( + data=dict(required=False, default=None), + ), + supports_check_mode=True + ) + result = dict(ping='pong') + if module.params['data']: + if module.params['data'] == 'crash': + raise Exception("boom") + result['ping'] = module.params['data'] + result['location'] = 'role: foo' + module.exit_json(**result) + + +if __name__ == '__main__': + main() diff --git a/test/integration/targets/module_precedence/roles_with_extension/foo/tasks/main.yml b/test/integration/targets/module_precedence/roles_with_extension/foo/tasks/main.yml new file mode 100644 index 0000000..985fc34 --- /dev/null +++ b/test/integration/targets/module_precedence/roles_with_extension/foo/tasks/main.yml @@ -0,0 +1,10 @@ +--- +- name: Use ping from inside foo role + ping: + register: result + +- name: Make sure that we used the ping module from the foo role + assert: + that: + - '"location" in result' + - 'result["location"] == "role: foo"' diff --git a/test/integration/targets/module_precedence/runme.sh b/test/integration/targets/module_precedence/runme.sh new file mode 100755 index 0000000..0f6a98f --- /dev/null +++ b/test/integration/targets/module_precedence/runme.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +set -eux + +# Standard ping module +ansible-playbook modules_test.yml -i ../../inventory -v "$@" + +# Library path ping module +ANSIBLE_LIBRARY=lib_with_extension ansible-playbook modules_test_envvar.yml -i ../../inventory -v "$@" +ANSIBLE_LIBRARY=lib_no_extension ansible-playbook modules_test_envvar.yml -i ../../inventory -v "$@" + +# ping module from role +ANSIBLE_ROLES_PATH=roles_with_extension ansible-playbook modules_test_role.yml -i ../../inventory -v "$@" +ANSIBLE_ROLES_PATH=roles_no_extension ansible-playbook modules_test_role.yml -i ../../inventory -v "$@" + +# ping module from role when there's a library path module too +ANSIBLE_LIBRARY=lib_no_extension ANSIBLE_ROLES_PATH=roles_with_extension ansible-playbook modules_test_role.yml -i ../../inventory -v "$@" +ANSIBLE_LIBRARY=lib_with_extension ANSIBLE_ROLES_PATH=roles_with_extension ansible-playbook modules_test_role.yml -i ../../inventory -v "$@" +ANSIBLE_LIBRARY=lib_no_extension ANSIBLE_ROLES_PATH=roles_no_extension ansible-playbook modules_test_role.yml -i ../../inventory -v "$@" +ANSIBLE_LIBRARY=lib_with_extension ANSIBLE_ROLES_PATH=roles_no_extension ansible-playbook modules_test_role.yml -i ../../inventory -v "$@" + +# ping module in multiple roles: Note that this will use the first module found +# which is the current way things work but may not be the best way +ANSIBLE_LIBRARY=lib_no_extension ANSIBLE_ROLES_PATH=multiple_roles ansible-playbook modules_test_multiple_roles.yml -i ../../inventory -v "$@" +ANSIBLE_LIBRARY=lib_with_extension ANSIBLE_ROLES_PATH=multiple_roles ansible-playbook modules_test_multiple_roles.yml -i ../../inventory -v "$@" +ANSIBLE_LIBRARY=lib_no_extension ANSIBLE_ROLES_PATH=multiple_roles ansible-playbook modules_test_multiple_roles.yml -i ../../inventory -v "$@" +ANSIBLE_LIBRARY=lib_with_extension ANSIBLE_ROLES_PATH=multiple_roles ansible-playbook modules_test_multiple_roles.yml -i ../../inventory -v "$@" + +# And prove that with multiple roles, it's the order the roles are listed in the play that matters +ANSIBLE_LIBRARY=lib_with_extension ANSIBLE_ROLES_PATH=multiple_roles ansible-playbook modules_test_multiple_roles_reverse_order.yml -i ../../inventory -v "$@" + +# Tests for MODULE_IGNORE_EXTS. +# +# Very similar to two tests above, but adds a check to test extension +# precedence. Separate from the above playbooks because we *only* care about +# extensions here and 'a' will not exist when the above playbooks run with +# non-extension library/role paths. There is also no way to guarantee that +# these tests will be useful due to how the pluginloader seems to work. It uses +# os.listdir which returns things in an arbitrary order (likely dependent on +# filesystem). If it happens to return 'a.py' on the test node before it +# returns 'a.ini', then this test is pointless anyway because there's no chance +# that 'a.ini' would ever have run regardless of what MODULE_IGNORE_EXTS is set +# to. The hope is that we test across enough systems that one would fail this +# test if the MODULE_IGNORE_EXTS broke, but there is no guarantee. This would +# perhaps be better as a mocked unit test because of this but would require +# a fair bit of work to be feasible as none of that loader logic is tested at +# all right now. +ANSIBLE_LIBRARY=lib_with_extension ansible-playbook modules_test_envvar_ext.yml -i ../../inventory -v "$@" +ANSIBLE_ROLES_PATH=roles_with_extension ansible-playbook modules_test_role_ext.yml -i ../../inventory -v "$@" -- cgit v1.2.3