How to convince ansible-playbook to colorize output?

1,107 views
Skip to first unread message

Bryan Berry

unread,
Dec 11, 2014, 4:50:55 AM12/11/14
to ansible...@googlegroups.com
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

Brian Coca

unread,
Dec 11, 2014, 10:31:12 AM12/11/14
to ansible...@googlegroups.com
try setting the environment variable in your master's shell ANSIBLE_COLOR=True



--
Brian Coca

Michael DeHaan

unread,
Dec 11, 2014, 11:05:28 AM12/11/14
to ansible...@googlegroups.com
Actually, it's just

export ANSIBLE_FORCE_COLOR=True

unset the variable to remove the behavior





--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAJ5XC8mhWL0AhVSUq5JHHhOQ8HFdV1nS6N5F0emzdvYtLJzwng%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Bryan Berry

unread,
Dec 11, 2014, 12:33:25 PM12/11/14
to ansible...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages