Ansible为什么返回格式不同的ifconfig输出?

问题描述 投票:0回答:1

以下Ansible ad-hoc命令在主机上运行ifconfig

ansible all -i "192.168.3.5," -m shell -a "ifconfig" -u root

(注意以下输出中的MAC 00:aa:bb:cc:dd:11为小写)

192.168.3.5 | CHANGED | rc=0 >>
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.5  netmask 255.255.255.0  broadcast 0.0.0.0
        inet6 fe80::2ec:acff:fecd:e248  prefixlen 64  scopeid 0x20<link>
        ether 00:aa:bb:cc:dd:11  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16  memory 0xd0900000-d0920000 

[当我通过SSH或本地在主机上运行ifconfig时,输出的格式不同(请注意,MAC 00:AA:BB:CC:DD:11均为大写)

eth0      Link encap:Ethernet  HWaddr 00:AA:BB:CC:DD:11
          inet addr:192.168.3.5  Bcast:0.0.0.0  Mask:255.255.255.0
          inet6 addr: fe80::2ec:acff:fecd:e248/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1250659 errors:0 dropped:0 overruns:0 frame:0
          TX packets:572911 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1050302730 (1001.6 MiB)  TX bytes:88810961 (84.6 MiB)
          Interrupt:16 Memory:d0900000-d0920000

根本原因是什么? Ansible有没有办法以SSH /本地格式显示输出?

环境

ansible 2.9.7

配置文件=无

python版本= 3.7.4

目标主机192.168.3.5:Alpine Linux 3.10

linux ansible ansible-2.x ansible-facts ifconfig
1个回答
0
投票

问题运行which ifconfig确定每个命令的路径后,我发现Ansible使用/bin/ifconfig,而SSH使用/sbin/ifconfig

解决方案使用. /etc/profile为每个Ansible命令获取配置文件。例如:

ansible all -i "192.168.3.5," -m shell -a ". /etc/profile && ifconfig" -u root

请参阅此相关答案以获取更多解决方案:link


感谢Zeitounator的提示

© www.soinside.com 2019 - 2024. All rights reserved.