Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we print coloured output of Ansible tasks when Ansible is run through a shell script?

Tags:

bash

ansible

I have an Ansible playbook that is called from a bash script as show in the below snippet:

#!/bin/bash
# Name of script: execute_ansible

# Execute ansible playbook
ansible-playbook my_ansible_playbook

This script is executed as below:

bash execute_ansible

When executed with the above command, the Ansible playbook my_ansible_playbook is executed correctly. However, the colorised output that would have been displayed had the Ansible playbook been run from the command line directly is not visible.
Is there a way we can enable the colorised output to be visible when executed from the shell script?

like image 258
Moses Avatar asked Dec 31 '25 06:12

Moses


1 Answers

https://docs.ansible.com/ansible/latest/reference_appendices/config.html#ansible-force-color

You can either set the environment variable ANSIBLE_FORCE_COLOR to True, or set the config defaults.force_color to True in your ansible config file (local ansible.cfg, ~/.ansible.cfg or /etc/ansible/ansible.cfg)

like image 159
zigarn Avatar answered Jan 04 '26 21:01

zigarn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!