天高云淡 发表于 2018-1-2 17:19:58

ansible-playbook 主机变量2

# cat hosts  

  

10.1.162.18:322  
10.1.167.36:32200
  

  
# ssh-copy-id -i ~/.ssh/id_rsa.pub "-p 322 root@10.1.162.18 "
  
root@10.1.162.18's password:
  
Now try logging into the machine, with "ssh '-p 322 root@10.1.162.18 '", and check in:
  

  .ssh/authorized_keys
  

  
to make sure we haven't added extra keys that you weren't expecting.
  

  
# ansible web -m shell -a ifconfig -i hosts
  
10.1.162.18 | SUCCESS | rc=0 >>
  
eth0      Link encap:EthernetHWaddr 00:0C:29:21:BD:17
  inet addr:192.168.238.129Bcast:192.168.238.255Mask:255.255.255.0
  inet6 addr: fe80::20c:29ff:fe21:bd17/64 Scope:Link
  UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
  RX packets:301306 errors:0 dropped:0 overruns:0 frame:0
  TX packets:121768 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:1000
  RX bytes:364185541 (347.3 MiB)TX bytes:6774878 (6.4 MiB)
  Interrupt:19 Base address:0x2000
  

  
lo      Link encap:Local Loopback
  inet addr:127.0.0.1Mask:255.0.0.0
  inet6 addr: ::1/128 Scope:Host
  UP LOOPBACK RUNNINGMTU:65536Metric:1
  RX packets:8 errors:0 dropped:0 overruns:0 frame:0
  TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:0
  RX bytes:480 (480.0 b)TX bytes:480 (480.0 b)
  

  
10.1.167.36 | UNREACHABLE! => {
  "changed": false,
  "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n",
  "unreachable": true
  
}
页: [1]
查看完整版本: ansible-playbook 主机变量2