ansible -m shell -a 注意单引号和双引号

[esb@esbapp1 sbin]$ ./ansible -i esbhosts  esbgroup -m shell -a "echo $HOSTNAME"
10.2.229.105 | SUCCESS | rc=0 >>
esbapp1

10.2.229.103 | SUCCESS | rc=0 >>
esbapp1

10.2.229.104 | SUCCESS | rc=0 >>
esbapp1

10.2.229.102 | SUCCESS | rc=0 >>
esbapp1

10.2.229.101 | SUCCESS | rc=0 >>
esbapp1

10.2.229.106 | SUCCESS | rc=0 >>
esbapp1

[esb@esbapp1 sbin]$ ./ansible -i esbhosts  esbgroup -m shell -a 'echo $HOSTNAME'
10.2.229.105 | SUCCESS | rc=0 >>
esbapp5

10.2.229.102 | SUCCESS | rc=0 >>
esbapp2

10.2.229.104 | SUCCESS | rc=0 >>
esbapp4

10.2.229.103 | SUCCESS | rc=0 >>
esbapp3

10.2.229.101 | SUCCESS | rc=0 >>
esbapp1

10.2.229.106 | SUCCESS | rc=0 >>
esbapp6

[esb@esbapp1 sbin]$ 
原文地址:https://www.cnblogs.com/hzcya1995/p/13349102.html