Hello In my playbook I try to determine the locale of the target host using the following command
- name: get locale info
command: printenv LANG
register: my_loc
The strange thing is, the result changes depending on which control host I execute the playbook. If I run it from my CentOS 8 box i will get as result the value en_US.UTF-8, If I run it a CentOS7 machine I will get en_US.utf8. These values are the same as i would get in a shell of the console host. But I would expect to that the vales are computed on the target machine and thus should be the same independently from which control host I execute the playbook.
On the CentOS7 machine
[me]$ ansible --version
ansible 2.9.25
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/me/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Nov 16 2020, 22:23:17) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
[me]$ printenv LANG
en_US.utf8
On the CentOS8 machine
[me]$ ansible --version
ansible 2.9.25
config file = /home/me/ansible-toolbox/ansible.cfg
configured module search path = ['/home/me/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.6/site-packages/ansible
executable location = /usr/bin/ansible
python version = 3.6.8 (default, Sep 21 2021, 20:17:36) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]
[me]$ printenv LANG
en_US.UTF-8
The playbook looks like this
# playbook for experiments
---
- name: setup servers
hosts: all
tasks:
# make sure the system local is set to american English
- name: setting up as centos server
command: printenv LANG
register: my_loc
- name: show locale
debug:
var: my_loc.stdout
And I run it with the command
ansible-playbook -i 172.19.1.5 area51.yml
The output is in one case
PLAY [setup servers] *****************************************************************************
TASK [Gathering Facts] ****************************************************************************
ok: [172.19.1.5]
TASK [setting up as centos server] ***************************************************************
changed: [172.19.1.5]
TASK [show locale] ********************************************************************************
ok: [172.19.1.5] => {
"my_loc.stdout": "en_US.UTF-8"
}
PLAY RECAP ****************************************************************************************
172.19.1.5 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
And in the other case
PLAY [setup servers] ***************************************************************************************
TASK [Gathering Facts] **************************************************************************************
ok: [172.19.1.5]
TASK [setting up as centos server] *************************************************************************
changed: [172.19.1.5]
TASK [show locale] ******************************************************************************************
ok: [172.19.1.5] => {
"my_loc.stdout": "en_US.utf8"
}
PLAY RECAP **************************************************************************************************
172.19.1.5 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
I have tried the same thing with running the command ssh user@172.19.1.9 printenv LANG and got the same result thus I think it is not a problem with ansible.