Here is a simple custom module, but when I try to import the ansible.utils.color then I get the error:
`
No module named ansible.utils.color
`
It seems I cannot import from anywhere but within ansible.module_utils.xxx
Can anyone advise on this?
Here is the module code:
`
#!/usr/bin/python
-- coding: utf-8 --
#---- Logic Start ------------------------------------------------------------#
import sys
import ansible.utils.color
def main():
module.exit_json(changed=True, something_else=str(sys.modules), version=PB_ANSIBLE_VERSION)
#---- Import Ansible Utilities (Ansible Framework) ---------------------------#
from ansible.module_utils.basic import *
module = AnsibleModule(
argument_spec = dict(
state = dict(default=‘present’, choices=[‘present’, ‘absent’]),
name = dict(required=True),
enabled = dict(type=‘bool’),
something = dict(aliases=[‘whatever’])
)
)
try:
since ansible 2.1.x
PB_ANSIBLE_VERSION = module.ansible_version[0]
except:
PB_ANSIBLE_VERSION = ANSIBLE_VERSION[0]
if name == ‘main’:
main()
`