| 1 |
#!/usr/bin/python |
| 2 |
# issue #590: I am an Ansible new-style Python module that tries to use |
| 3 |
# ansible.module_utils.distro. |
| 4 |
|
| 5 |
import ansible |
| 6 |
from ansible.module_utils.basic import AnsibleModule |
| 7 |
|
| 8 |
def try_int(s): |
| 9 |
try: |
| 10 |
return int(s, 10) |
| 11 |
except ValueError: |
| 12 |
return s |
| 13 |
|
| 14 |
ansible_version = tuple(try_int(s) for s in ansible.__version__.split('.')) |
| 15 |
|
| 16 |
if ansible_version[:2] >= (2, 8): |
| 17 |
from ansible.module_utils import distro |
| 18 |
else: |
| 19 |
distro = None |
| 20 |
|
| 21 |
def main(): |
| 22 |
module = AnsibleModule(argument_spec={}) |
| 23 |
if ansible_version[:2] >= (2, 8): |
| 24 |
module.exit_json(info=distro.info()) |
| 25 |
else: |
| 26 |
module.exit_json(info={'id': None}) |
| 27 |
|
| 28 |
if __name__ == '__main__': |
| 29 |
main() |