How to convince ansible-playbook to colorize output?

Dear Ansiblists,

I have written a tool that wraps ansible-playbook to enforce a client’s fairly complex workflow and provides helper functions specific to their use case. The only thing that I lose by doing is the colorized output. Is there anyway I can trick ansible-playbook and other commands to output colorized output?

I use this invocation of subprocess.Popen to spawn the ansible playbook and flush the stdout

p = subprocess.Popen('ansible-playbook . . . ', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
flush_subprocess_stdout(p.stdout)

this function is located elsewhere

def flush_subprocess_stdout(stdout_fd):
lines =
while True:
line = stdout_fd.readline()
if not line:
break
lines.append(line)
print line.strip()
return lines

I found these lines in ansible-playbook, which appear to determine what output is colorized and which is not. I also looked at the display method in ansible.callbacks. It’s still not clear to me how I can convince ansible-playbook to colorize stdout. Any suggestions?

https://github.com/ansible/ansible/blob/devel/bin/ansible-playbook#L287-L303

Bryan

try setting the environment variable in your master's shell ANSIBLE_COLOR=True

Actually, it’s just

export ANSIBLE_FORCE_COLOR=True

unset the variable to remove the behavior

tks guys! that’s fantastic