Ansible giving "ansible.utils.display.initialize_locale has not been called" warning

Viewed 3505

I'm getting this warning ansible.utils.display.initialize_locale has not been called but I can't find documentation to fix it.

[WARNING]: ansible.utils.display.initialize_locale has not been called, this may result in incorrectly calculated text widths that can cause Display to print incorrect line lengths

Playbook:

- name: Create Docker Swarm Cluster
  hosts: localhost
  connection: local

  vars:
    # Project name to used as part of resource names
    project_name: swarm

    # The location of the Azure resources
    location: eastus

Running it with:

ansible-playbook provision.yml

Using python3 -m venv env to set up the environment.

And ansible version:

$ ansible --version
ansible [core 2.11.1] 
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/pomatti/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/pomatti/projects/personal/docker-swarm-cluster-with-ansible/env/lib/python3.8/site-packages/ansible
  ansible collection location = /home/pomatti/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/pomatti/projects/personal/docker-swarm-cluster-with-ansible/env/bin/ansible
  python version = 3.8.5 (default, May 27 2021, 13:30:53) [GCC 9.3.0]
  jinja version = 3.0.1
  libyaml = True
2 Answers

In Ansible, there is a file named: /usr/local/lib///ansible/utils/display.py

and that's where the initialize_locale() function resides - it's hard to tell where Ansible is calling it, but it just looks to see if the locale is found / initialized (with variables). If it cannot define the locale, it defines LOCALE_INITIALIZATION_ERR (to true). There is a conditional later on that checks the variable, and if True, simply outputs a/the annoying warning. TBH, rather than dig any deeper, since this is obviously a weird error that they will fix at some point, I just commented out the function call that outputs the warning (in two places), and just replaced it with "pass" (do nothing). A little hacky, but warnings have now disappeared.

The interesting thing is that the warnings did not appear when using AWX on this control node !

In the python file display.py showing in the error add the below function: /home/user/.local/lib/python3.8/site-packages/ansible/utils/display.py

def initialize_locale(): return True

Related