Hello在我的剧本中,我尝试使用以下命令
确定目标主机的区域设置- name: get locale info
command: printenv LANG
register: my_loc
奇怪的是,结果的变化取决于我执行剧本的控制主机。如果我从CentOS 8盒子上运行它,我将得到结果值en_US。utf - 8,如果我在CentOS7机器上运行它,我将得到en_US.utf8.这些值与我在控制台主机的shell中获得的值相同。但是我希望这些值是在目标机器上计算的,因此应该与我执行剧本的控制主机无关。
在CentOS7机器上
[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
在CentOS8机器上
[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
剧本是这样的
# 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
我用命令
运行它ansible-playbook -i 172.19.1.5 area51.yml
输出在一个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
另一种情况
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
我已经尝试了同样的事情运行命令ssh user@172.19.1.9 printenv LANG,并得到了相同的结果,因此我认为这不是一个问题与ansible。
问题似乎是ssh将区域设置从控制主机传输到远程主机,这将在CentOS中产生远程主机将镜像控制主机的区域设置而不是使用默认区域设置的效果。
看
https://github.com/ansible/ansible/issues/10698