# Importing ansible.utils.color within custom modules

**URL:** <https://forum.ansible.com/t/importing-ansible-utils-color-within-custom-modules/24057>\
**Category:** Ansible Project\
**Created:** [March 24, 2017, 1:54pm UTC](https://forum.ansible.com/t/importing-ansible-utils-color-within-custom-modules/24057 "2017-03-24T13:54:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Wadleigh](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@John\_Wadleigh](https://forum.ansible.com/u/John_Wadleigh)\
**Post date:** [March 24, 2017, 1:54pm UTC](https://forum.ansible.com/t/importing-ansible-utils-color-within-custom-modules/24057/1 "2017-03-24T13:54:05Z")

</div>

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()

`

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [March 24, 2017, 3:48pm UTC](https://forum.ansible.com/t/importing-ansible-utils-color-within-custom-modules/24057/2 "2017-03-24T15:48:03Z")

</div>

modules cannot rely on any ansible code outside module\_utils, this is  
'special' and get's bundled into them, it is reserved for small common  
libraries for modules.

To do what you want, you need ansible installed on all the targets.
