Run ansible-playbook within AAP EE, without color output

, ,

We have to run an Ansible playbook of a third party vendor within an AAP execution environment.

This playbook needs a custom inventory, which we cannot register as an AAP inventory. So we run “ansible-playbook --inventory /custom/inventory /path/to/3rdparty.yml” either using ansible.builtin.shell or ansible.builtin.command from a wrapper playbook.

The execution itself works fine and gives us the expected result. The biggest problem we have so far is output capturing and output formatting of the ansible-playbook command: We cannot manage to get rid of the escape sequences which are used by ansible-playbook for coloring the output. This makes the Job output unreadable in AAP.

What I tried so far:

  1. put a custom ansible.cfg into the project and set nocolor=True
    • Debug output shows, that the ansible.cfg file is used, but the nocolor setting is not honoured → ansible-playbook still produces colorized output
    • trying it out in an interactive session of the EE container, it works fine
  2. add ANSIBLE_NOCOLOR and NO_COLOR environment vars to the ansible.builtin.shell parameters.
    • these do not seem to be honoured either → still colorized output
  3. all kind of weird stuff you can find on other forums
    • pipe the output of ansible-playbook through cat etc. → still colorized output
  4. put the ansible-playbook call into an extra shell script, setting the environment vars there and run this shell script via ansible.builtin.shell
    • no change to the situation

Is there any other way I can run a custom playbook from a wrapper playbook on AAP without the color escape sequences added to the output?

AAP version as far as I can see is 4.4.4
Ansible version in the EE is 2.15.11

Thanks for any hint.
Cheers,
Chris

That indicates that ANSIBLE_FORCE_COLOR is also set somehow, try also adding ANSIBLE_FORCE_COLOR: "0" alongside ANSIBLE_NOCOLOR and NO_COLOR to see if that changes anything.

Hey Sivel,

seems I relied on the documented default value for ANSIBLE_FORCE_COLOR being “False”, and only once forced it to “False” at the very beginning of my journey, but obviously not in the right combination with the other COLOR environment vars.
When checking the actual environment, I just saw that it is set to True, although there is no obvious ansible.cfg anywhere in my EE.

This seems to remove the color specific ESC sequences from the output. The task headers and the Recap look clean now.

Now there are still a lot of lines with this pattern in the output:

"\u001b[Ke30=\u001b[4D\u001b[K\u001b[KeyJ1XYZXYZDUMMYDUMMYXYZXYZJ9\u001b[64D\u001b[K",

This could be solved thanks to your hints in this thread: Garbled output from nested playbooks · Issue #1317 · ansible/ansible-runner · GitHub

Thanks a lot.
Cheers,
Chris